Advertisement
Guest User

Don't Argue With Me

a guest
Sep 9th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class AddingValuesInALoop
  4. {
  5.     public static void main(String[] Args)
  6.     {
  7.         int entry = -1, total = 0;
  8.         Scanner k = new Scanner(System.in);
  9.         System.out.println("I will add up the numbers you give me.");
  10.  
  11.         while (entry != 0)
  12.         {
  13.             System.out.print("Number: ");
  14.             entry = k.nextInt();
  15.             total += entry;
  16.             if (entry != 0)
  17.             {
  18.                 System.out.println("The total so far is " + total);
  19.             }
  20.         }
  21.         System.out.println("\nThe total is " + total);
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement