编程语言
首页 > 编程语言> > JAVA实现石头剪刀布

JAVA实现石头剪刀布

作者:互联网

import java.util.Random;
import java.util.Scanner;

public class test20 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请出拳:");
String s = scanner.nextLine();
if (s.equals("石头")){
System.out.println("您使出了石头");
}
if (s.equals("剪刀")){
System.out.println("您使出了剪刀");
}
if (s.equals("布")){
System.out.println("您使出了布");
}
Random random = new Random();
int i = random.nextInt(3);
System.out.println(i);
switch (i){
case 0:
String s1 = "石头";
System.out.println("对方使出了"+s1);
if (s.equals("石头")&&s1.equals("石头")){
System.out.println("对局平局");
}
if (s.equals("剪刀")&&s1.equals("石头")){
System.out.println("您输了");
}
if (s.equals("布")&&s1.equals("石头")){
System.out.println("您赢了");
}
break;
case 1:
String s2 = "剪刀";
System.out.println("对方使出了"+s2);
if (s.equals("石头")&&s2.equals("剪刀")){
System.out.println("您赢了");
}
if (s.equals("剪刀")&&s2.equals("剪刀")){
System.out.println("对局平局");
}
if (s.equals("布")&&s2.equals("剪刀")){
System.out.println("您输了");
}
break;
case 2:
String s3 = "布";
System.out.println("对方使出了"+s3);
if (s.equals("石头")&&s3.equals("布")){
System.out.println("您输了");
}
if (s.equals("剪刀")&&s3.equals("布")){
System.out.println("您赢了");
}
if (s.equals("布")&&s3.equals("布")){
System.out.println("对局平局");
}
break;
}

}
}

标签:JAVA,System,equals,&&,println,石头,剪刀,out
来源: https://www.cnblogs.com/KELIANG/p/16474660.html