猜拳游戏


public class While3 {
			//猜拳游戏 3局2胜
	public static void main(String[] args) {		
		java.util.Scanner sc=new java.util.Scanner(System.in);		
		//w1胜利的局数
		int a=0;
		//w2胜利的局数
		int b=0;		
		while(true){		
			System.out.println("w1输入(石头1  剪刀2 布3)");
			int w1 =sc.nextInt();
			System.out.println("w2输入(石头1  剪刀2 布3)");
			int w2=sc.nextInt();
			//判断输入的数是否合法
			if(w1>=1&&w1<=3&&w2>=1&&w2<=3){
				//w1赢的情况
				if(w1==1&&w2==2||w1==2&&w2==3||w1==3&&w2==1){					
					a++;
					if(a==2){
						System.out.println("w1 win");
						break;
					}
				}//w2胜利的情况
				else if(w2==1&&w1==2||w2==2&&w1==3||w2==3&&w1==1){
					b++;
					if(b==2){
						System.out.println("w2 win");
						break;
					}
				}
				//平局的情况
				if(w1==w2){
					continue;
				}				
			}
			else{
				System.out.println("输入不合法");
				continue;
				
			}
	
	}

}
}

 

你可能感兴趣的:(java)