Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Lesson 17 Coding Activity 1
- * Write a program that will input a list of test scores in from the keyboard.
- * When the user enters -1, print the average.
- *
- * What do you need to be careful about when using -1 to stop a loop?
- *
- * Sample Run:
- * Enter the Scores:
- * 45
- * 100
- * -1
- *
- * The average is: 72.5
- *
- *
- */
- import java.util.Scanner;
- import java.lang.Math;
- class Lesson_17_Activity_One {
- public static void main(String[] args)
- {
- Scanner scan = new Scanner(System.in);
- System.out.println("Enter the Scores:");
- int x = 0;
- int count = -1;
- double total = 1;
- while ( x != -1)
- {
- x = scan.nextInt();
- count++;
- total = total + x;
- }
- System.out.println("The average is: " + (double)(total/count));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment