Discuss / Java / 交作业啦

交作业啦

Topic source

杨森-ys

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

/*

通过观察,当赢得时候choise-rando等于-1,2的时候赢

0的时候平

-2,1的时候负

*/

public class SwitchDemo {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

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

System.out.println(" 1: Rock");  //石头

System.out.println(" 2: Scissors");  //剪刀

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

int input_choice = (int) scanner.nextDouble();

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

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

int choice = input_choice - random;

System.out.println("系统出的:"+random);

switch (choice) {

case 0:

System.out.println("平局");

break;

case -1:

case 2:

System.out.println("你赢了");

case -2:

case 1:

System.out.println("你输了");

}

}

}


  • 1

Reply