Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner; // Scanner import
- public class Main { // program begins
- public static void main(String[] args) {
- Scanner input = new Scanner (System.in); // Scanner declaration
- // variable declaration
- int answer;
- final int ans1 = 0, ans2 = 6, ans3 = 2, ans4 = 1;
- System.out.println("How many wins does Guerrilla have? Your options: 0, 6, 2, 1 or 999 to exit.");
- answer = input.nextInt();
- while (answer != 999) { //while loop being used as a continuous loop, and it can be exited when 999 is entered.
- //if statements being used to compare the answer the user entered with the ones that have been initialised within program
- if(answer == ans1) {
- System.out.println("0 is the incorrect answer, please try again.");
- }
- if(answer == ans2) {
- System.out.println("6 is the correct answer. Congrats!.");
- }
- if(answer == ans3) {
- System.out.println("2 is the incorrect answer, please try again.");
- }
- if(answer == ans4) {
- System.out.println("0 is the incorrect answer, please try again.");
- }
- //updating variable within loop
- System.out.println("How many wins does Guerrilla have? Your options: 0, 6, 2, 1 or 999 to exit.");
- answer = input.nextInt();
- } //while loop ends
- System.out.println("Thank you for answering."); //goodbye statement, will appear when 999 is entered
- }
- } //program ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement