Advertisement
thotfrnk

atz multiple choice.java

Nov 20th, 2022
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. import java.util.Scanner; // Scanner import
  2. public class Main { // program begins
  3.     public static void main(String[] args) {
  4.  
  5.         Scanner input = new Scanner (System.in); // Scanner declaration
  6.  
  7.         // variable declaration
  8.  
  9.         int answer;
  10.         final int ans1 = 0, ans2 = 6, ans3 = 2, ans4 = 1;
  11.  
  12.         System.out.println("How many wins does Guerrilla have? Your options: 0, 6, 2, 1 or 999 to exit.");
  13.         answer = input.nextInt();
  14.  
  15.         while (answer != 999) { //while loop being used as a continuous loop, and it can be exited when 999 is entered.
  16.  
  17.             //if statements being used to compare the answer the user entered with the ones that have been initialised within program
  18.             if(answer == ans1) {
  19.                 System.out.println("0 is the incorrect answer, please try again.");
  20.             }
  21.             if(answer == ans2) {
  22.                 System.out.println("6 is the correct answer. Congrats!.");
  23.             }
  24.             if(answer == ans3) {
  25.                 System.out.println("2 is the incorrect answer, please try again.");
  26.             }
  27.             if(answer == ans4) {
  28.                 System.out.println("0 is the incorrect answer, please try again.");
  29.             }
  30.             //updating variable within loop
  31.             System.out.println("How many wins does Guerrilla have? Your options: 0, 6, 2, 1 or 999 to exit.");
  32.             answer = input.nextInt();
  33.         } //while loop ends
  34.  
  35.         System.out.println("Thank you for answering."); //goodbye statement, will appear when 999 is entered
  36.     }
  37. } //program ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement