Discuss / Java / 加了个小判断!!

加了个小判断!!

Topic source

import java.util.Scanner;

public class HELLO {

     public static void main(String[] args) {

    System.out.println("please input:");

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

    System.out.println("2:SCISSORS");

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

    boolean flag=true;

    while(flag){

        int choice=0;

        Scanner scanner= new Scanner(System.in);

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

        choice=scanner.nextInt();

        if( !(choice>0 && choice <4) ){

            System.out.println("error input!!!");

            continue;

        }    

        int a=(int)(Math.random()*3);

        int random=1+a;

        switch(choice)

        {

            case 1: 

            {

                if(random>2)

                {   

                    System.out.println("you fail");

                    break;

                }

                else if(random == 1){

                    System.out.println("draw, play it again!");

                    break;

                }

                else{

                    System.out.println("you win!!!!");

                    break;

                }

            }

            case 2:

            {

                if(random==1){

                    System.out.println("you fail");

                    break;

                }

                else if(random==2){

                    System.out.println("draw, play it again!");

                    break;

                }

                else{

                    System.out.println("you win!!!!");

                    break;

                }

            }

            case 3:{

                if(random==3){

                    System.out.println("draw, play it again!");

                    break;

                }

                else if(random==2){

                    System.out.println("you fail");

                    break;

                }

                else{

                    System.out.println("you win!!");

                    break;

                }

            }

        }

        if(choice>0 && choice<4){

            switch(random)

            {   

                case 1 :System.out.println("your competitor is "+random+" :ROCK.");break;

                case 2 :System.out.println("your competitor is "+random+" :SCISSORS.");break;

                case 3 :System.out.println("your competitor is "+random+" :PAPEFR.");break;

            }

        }

    }

 }

}


  • 1

Reply