Discuss / Java / 剪刀石头布

剪刀石头布

Topic source

lina19820525

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

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

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

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

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

// 用户输入:

int choice = 0;

Scanner sc = new Scanner(System.in);

System.out.print("please show your hand:");

int cs = sc.nextInt();

// 计算机随机数 1, 2, 3:

if(cs>=1 && cs<=3) {

int random = (int)(1.5 + Math.random()*3);

System.out.println("random:"+random);

if(cs-random<0) {

choice = -1;

}else if(cs-random>0){

choice = 1;

  }

switch (choice) {

// TODO:

    case 1 -> System.out.println("you are won!");

    case -1 -> System.out.println("you are fall!");

    case 0 -> System.out.println("safe!");

    default -> System.out.println("please show your hand");

}

}else {

System.out.println("please show your hand1,2,3");

}

老哥,你这有问题啊,如果我输入的是3也就是布,随机的是2也就是剪刀,怎么会判定我赢呢?


  • 1

Reply