//做一个剪刀石头布的对战小程序
import java.util.Scanner;
public class Work7{
public static void main(String[] args){
int computer = (int)(Math.random()*3) + 1;
int user;
do{
System.out.println("游戏规则:1:剪刀 2:石头 3:布 请出拳 1 -3之间");
Scanner input = new Scanner(System.in);
user = input.nextInt();
}while(user !=1 && user !=2 && user !=3);
if(computer == user){
System.out.println("我们打平");
}else if(((computer == 1) & (user != 3)) || ((computer == 2) & (user != 1)) ||((computer == 3) & (user != 2))){
System.out.println("厉害哦兄弟,你赢了");
}else{
System.out.println("唉,输了,得加油兄弟!");
}
System.out.println("电脑出:" + computer);
}
import java.util.Scanner;
public class Work7{
public static void main(String[] args){
int computer = (int)(Math.random()*3) + 1;
int user;
do{
System.out.println("游戏规则:1:剪刀 2:石头 3:布 请出拳 1 -3之间");
Scanner input = new Scanner(System.in);
user = input.nextInt();
}while(user !=1 && user !=2 && user !=3);
if(computer == user){
System.out.println("我们打平");
}else if(((computer == 1) & (user != 3)) || ((computer == 2) & (user != 1)) ||((computer == 3) & (user != 2))){
System.out.println("厉害哦兄弟,你赢了");
}else{
System.out.println("唉,输了,得加油兄弟!");
}
System.out.println("电脑出:" + computer);
}
}
若有不正之处,请多多谅解并欢迎批评指正。
请尊重作者劳动成果,转载请标明原文链接:
http://blog.csdn.net/weishimeng17