• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Jun 20th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. Scanner scan = new Scanner(System.in);
2.
3.         System.out.println("Would you like to play a game called Threes? Y/N");
4.         String answer = scan.nextLine();        //Simple yes or no
5.
7.             System.out.println("OK, want to know how it works? Y/N");
10.                 System.out.println("OK, Enter a single number.");
11.
12.                 int mistake = 0;    //Used as a counter for number of division mistakes made
13.                 int numstart = scan.nextInt();  //First number input
14.                 int current = numstart;     //Current number displayed - starts as the first number
15.
16.                 System.out.println("Enter 1 or -1 if you're adding or subtracting, and 0 to divide.");
17.                 System.out.println(numstart);       //Displays first number input
18.                 int input = scan.nextInt();     //First function performed by user
19.
20.                 while (current != 1) {      //The game will run until the number '1' is reached
21.                     if (input == 1) {       //If '1' is input, add one to the number, and display new number
22.                         current++;
23.                         System.out.println(current);
24.                         input = scan.nextInt();
25.                     }
26.                     if (input == -1) {      //If '-1' is input, subtract one from the number, and display new number
27.                         current--;
28.                         System.out.println(current);
29.                         input = scan.nextInt();
30.                     }
31.                     if (input == 0) {       //If '0' is input, try to divide
32.                         if (current % 3 != 0 && current != 1) {     //If you can't divide by three, try again
33.                             System.out.println("Try again.");
34.                             mistake++;
35.                             input = scan.nextInt();
36.                         }
37.                         if (current % 3 == 0) {     //If you can divide, do it and display new number
38.                             current = current / 3;
39.                             System.out.println(current);
40.                             input = scan.nextInt();
41.                         }
42.                     }
43.                     if (input == 69 || input == 666)     //Cheat code! If you input 69 or 666, you automatically win
44.                         break;
45.                     if (((input > 1) && (input != 69) && (input != 666)) || input < -1) {        //If input is not valid, try again and display error
46.                         System.out.println("Error - wrong input.");
47.                         input = scan.nextInt();
48.                     }
49.                 }
50.                 System.out.println("You Win! Mistakes: " + mistake + "n");        //Will display a win condition, and amount of division errors
51.                 System.out.println("Thank you for playing Threes n - Chris Burbach");
52.             }
53.             System.out.println("Credits? Y/N");
54.             String credits = scan.nextLine();
55.
56.             if(credits.contains("Y")||credits.contains("y"))
57.             {
58.                 System.out.println("n***********************************************************************");
59.                 System.out.println("*Threes: a game of dividing by three - inspired by my boredom in class*");
60.                 System.out.println("***********************************************************************");
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top