Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class AddingValuesInALoop
- {
- public static void main(String[] Args)
- {
- int entry = -1, total = 0;
- Scanner k = new Scanner(System.in);
- System.out.println("I will add up the numbers you give me.");
- while (entry != 0)
- {
- System.out.print("Number: ");
- entry = k.nextInt();
- total += entry;
- if (entry != 0)
- {
- System.out.println("The total so far is " + total);
- }
- }
- System.out.println("\nThe total is " + total);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement