Advertisement
Guest User

Untitled

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