Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Cookies
- {
- public static void main(String[] args)
- {
- //We need 30 cookies
- //asks for name and how many cookies you will bring in :)
- Scanner scanner = new Scanner(System.in);
- int cookies = 0;
- int numCookies = 0;
- while(numCookies != -1)
- {
- //ask for a name
- System.out.print("Name: ");
- String name = scanner.next();
- //ask for how many cookies
- System.out.print("How many cookies are you bringing? (Enter -1 to exit)");
- numCookies = scanner.nextInt();
- if(numCookies == -1)
- {
- System.out.println("Thank you. You, as a class are bringing in " + cookies + " cookies.");
- }
- else
- {
- //report our cookie total
- cookies = numCookies + cookies;
- System.out.println(name + ", you have agreen to bring in " + numCookies + " cookies, for a total of " + cookies + " cookies.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement