package 完美;
import java.util.*;
public class txt9 {
public static void main(String[] args){
System.out.println("...欢迎来到猜拳游戏。。。 ");
System.out.println("1。石头,2.剪刀,3.布");
System.out.println("...游戏开始请出拳...");
//人出拳
Scanner in=new Scanner(System.in);
int people=in.nextInt();
switch(people){
case 1:
System.out.println("你出的是石头");
case 2:
System.out.println("你出的是剪刀");
case 3:
System.out.println("你出的是布");
}
//电脑随机出拳
int computer=(int)(Math.random()*3)+1;
switch(computer){
case 1:
System.out.println("电脑出的是石头");
case 2:
System.out.println("电脑出的是剪刀");
case 3:
System.out.println("电脑出的是布");
}
//判断输赢
if(people==computer){
System.out.println("平局再来一次");
}else if(people==1&&computer==3||people==2&&computer==1||people==3&&computer==2){
System.out.println(" 哈哈你输了");
}else{
System.out.println("恭喜你你赢了");
}
}
}
我运行的结果是为什么是乱的想不通请指导
...欢迎来到猜拳游戏。。。
1。石头,2.剪刀,3.布
...游戏开始请出拳...
2
你出的是剪刀
你出的是布
电脑出的是布
恭喜你你赢了
switch语句中,每个case分支需要添加break语句。
我给你改了下,你看看:
public static void main(String[] args) {谢谢这位大神,不过为什么忘写break,MyEclipse没有提示错误?