package com.itranswarp.learnjava;
import java.util.Scanner;
/**
* switch实现石头/剪子/布并判断胜负
*/
public class Main {
public static void main(String[] args) {
// 用户输入:
int choice = 0;
Scanner sc = new Scanner(System.in);
do {
System.out.println("please choice:");
System.out.println(" 1: Rock");
System.out.println(" 2: Scissors");
System.out.println(" 3: Paper");
choice=sc.nextInt();
}while(choice<0||choice>3);
// 计算机随机数 1, 2, 3:
int random = 1 + (int) Math.random() * 3;
choice=choice-random;
System.out.println(random);
switch (choice) {
// TODO:
case 1 :
System.out.println("lose");
break;
case 2:
System.out.println("win");
case 0:
System.out.println("equal");
case -1:
}
Sign in to make a reply
欢愉-啊哈
package com.itranswarp.learnjava;
import java.util.Scanner;
/**
* switch实现石头/剪子/布并判断胜负
*/
public class Main {
public static void main(String[] args) {
// 用户输入:
int choice = 0;
Scanner sc = new Scanner(System.in);
do {
System.out.println("please choice:");
System.out.println(" 1: Rock");
System.out.println(" 2: Scissors");
System.out.println(" 3: Paper");
choice=sc.nextInt();
}while(choice<0||choice>3);
// 计算机随机数 1, 2, 3:
int random = 1 + (int) Math.random() * 3;
choice=choice-random;
System.out.println(random);
switch (choice) {
// TODO:
case 1 :
System.out.println("lose");
break;
case 2:
System.out.println("win");
break;
case 0:
System.out.println("equal");
break;
case -1:
System.out.println("win");
break;
}
}
}