import java.util.Scanner; public class TestDoWhile { /** Main method */ public static void main(String[] args) { int data; int sum = 0; // Create a Scanner Scanner input = new Scanner(System.in); // Keep reading data until the input is 0 do { // Read the next data System.out.print( "Enter an integer (the input ends if it is 0): "); data = input.nextInt(); sum += data; } while (FILL_CODE_OR_CLICK_ANSWER); System.out.println("The sum is " + sum); } } // LiveExample is used exclusively throughout the LIANG Revel books
  
JDK8>javac TestDoWhile.java Compiled successful JDK8>java TestDoWhile Enter an integer (the input ends if it is 0): 3 Enter an integer (the input ends if it is 0): 5 Enter an integer (the input ends if it is 0): 6 Enter an integer (the input ends if it is 0): 0 The sum is 14 JDK8>