Advertisement
MrsMcLead

While Sentinel

Feb 12th, 2014
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Cookies
  4. {
  5.  public static void main(String[] args)
  6.  {
  7.  //We need 30 cookies
  8.  //asks for name and how many cookies you will bring in :)
  9.    
  10.   Scanner scanner = new Scanner(System.in);
  11.   int cookies = 0;
  12.   int numCookies = 0;
  13.  
  14.   while(numCookies != -1)
  15.   {
  16.    //ask for a name
  17.     System.out.print("Name: ");
  18.     String name = scanner.next();
  19.    
  20.    
  21.    //ask for how many cookies
  22.     System.out.print("How many cookies are you bringing? (Enter -1 to exit)");
  23.     numCookies = scanner.nextInt();
  24.    
  25.     if(numCookies == -1)
  26.     {
  27.      System.out.println("Thank you. You, as a class are bringing in " + cookies + " cookies.");
  28.     }
  29.    
  30.     else
  31.     {
  32.     //report our cookie total
  33.     cookies = numCookies + cookies;
  34.    
  35.     System.out.println(name + ", you have agreen to bring in " + numCookies + " cookies, for a total of " + cookies + " cookies.");
  36.     }
  37.   }
  38.      
  39.      
  40.  }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement