import java.util.Scanner;
public class Main {
public static void main(String[] args) {
float weight;
float height;
String result = "";
Scanner scanner = new Scanner(System.in);
System.out.println("请选择");
System.out.println("1.石头");
System.out.println("2.剪子");
System.out.println("3.布");
//用户输入选择
int sel = scanner.nextInt();
//生成随机数
int random = (int)(Math.random()*3 + 1);
System.out.println(random);
//处理
switch (sel) {
// TODO:
case 1:
//我出的石头
switch (random) {
//随机数出石头
result = "平局!";
break;
case 2:
//随机数出的剪子
result = "你赢了!";
case 3:
//随机数出的布
result = "你输了!";
}
;
//建立两个字符串
String outputSel = "";
String outputRandom = "";
//输出结果转换成汉字
switch(sel){
outputSel = "石头";
outputSel = "剪子";
outputSel = "布";
switch(random){
outputRandom = "石头";
outputRandom = "剪子";
outputRandom = "布";
System.out.println("你选择了 " + outputSel);
System.out.println("我选择了 " + outputRandom);
System.out.println(result);
Sign in to make a reply
无名冷夜
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
float weight;
float height;
String result = "";
Scanner scanner = new Scanner(System.in);
System.out.println("请选择");
System.out.println("1.石头");
System.out.println("2.剪子");
System.out.println("3.布");
//用户输入选择
int sel = scanner.nextInt();
//生成随机数
int random = (int)(Math.random()*3 + 1);
System.out.println(random);
//处理
switch (sel) {
// TODO:
case 1:
//我出的石头
switch (random) {
case 1:
//随机数出石头
result = "平局!";
break;
case 2:
//随机数出的剪子
result = "你赢了!";
break;
case 3:
//随机数出的布
result = "你输了!";
break;
}
;
break;
case 2:
switch (random) {
case 1:
result = "你输了!";
break;
case 2:
result = "平局!";
break;
case 3:
result = "你赢了!";
break;
}
;
break;
case 3:
switch (random) {
case 1:
result = "你输了!";
break;
case 2:
result = "你赢了!";
break;
case 3:
result = "平局!";
break;
}
;
break;
}
//建立两个字符串
String outputSel = "";
String outputRandom = "";
//输出结果转换成汉字
switch(sel){
case 1:
outputSel = "石头";
break;
case 2:
outputSel = "剪子";
break;
case 3:
outputSel = "布";
break;
}
//输出结果转换成汉字
switch(random){
case 1:
outputRandom = "石头";
break;
case 2:
outputRandom = "剪子";
break;
case 3:
outputRandom = "布";
break;
}
System.out.println("你选择了 " + outputSel);
System.out.println("我选择了 " + outputRandom);
System.out.println(result);
}
}