Discuss / Java / Solution1

Solution1

Topic source

夜游蛇

#1 Created at ... [Delete] [Delete and Lock User]

import java.util.Scanner;

public class Solution1 {

    public static void main (String[] args) {

        Scanner input = new Scanner(System.in);

        System.out.println("Our game is beginning");

        boolean flag = true;

        while(flag) {

            System.out.println("Make your choice: ");

            System.out.println("1 ROCK");

            System.out.println("2 SCISSOR");

            System.out.println("3 PAPER");

            System.out.println("0 QUIT");

            int choice = input.nextInt();

            flag = (choice != 0);

            int god;

            if (choice == 0)

                god = 0;

            else 

                god = (int)(Math.random()*3) + 1;

            String output = switch(god) {

                case 1 -> "You win! ";

                case 2 -> "You lose!";

                case 3 -> "This is a draw";

                default -> "You've quit!";

            };

            System.out.println(output);

            System.out.println();

        }

        input.close();

    }

}


  • 1

Reply