CounterControlledWhileLoopVersionB

CounterControlledWhileLoopVersionB - //Line 2 sum = 0;...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//Counter-controlled while loop / import java.util.*; i public class CounterControlledWhileLoopVersionB { static Scanner console = new Scanner(System.in); public static void main (String[] args) { int limit; //store the number of items //in the list int number; //variable to store the number int sum; //variable to store the sum int counter; //loop control variable System.out.println("Line 1: Enter the data for " + "processing."); //Line 1 limit = console.nextInt();
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: //Line 2 sum = 0; //Line 3 counter = 0; //Line 4 while (counter < limit) //Line 5 { sum = sum + console.nextInt(); ; //Line 6 counter++; //Line 7 } System.out.printf("Line 8: The sum of the %d " + "numbers = %d%n", limit, sum); //Line 8 if (counter != 0) //Line 9 System.out.printf("Line 10: The average = %d%n", (sum / counter)); //Line 10 else //Line 11 System.out.println("Line 12: No input."); //Line 12 } }...
View Full Document

Ask a homework question - tutors are online