第一种
package 石头剪刀布;
import java.util.Scanner;
public class sbj1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
System.out.println("请输入你出的类型");
String s1=sc.nextLine();
String s2=sc.nextLine();
String s3;
if (!s1.equals(s2)) {
if (s1.equals("石头") && s2.equals("剪刀")) {
s3="你赢了";
} else if (s1.equals("剪刀") && s2.equals("布")) {
s3="你赢了";
} else if (s1.equals("布") && s2.equals("石头")) {
s3="你赢了";
} else {
s3="我赢了";
}
}else{
s3="平了";
}
print(s1,s2,s3);
}
public static void print(String...arr){
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
}
第二种
package 石头剪刀布;
import java.util.Random;
import java.util.regex.Pattern;
public class sjb {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Random r = new Random();
int x = r.nextInt(3);
Random r1 = new Random();
int y = r1.nextInt(3);
String[] arr = { "石头", "剪刀", "布" };
System.out.println("你出" + arr[x]);
String a = arr[x];
System.out.println("我出" + arr[y]);
String b = arr[y];
if (!a.equals(b)) {
if (a == arr[0] && b == arr[1]) {
System.out.println("你赢了");
} else if (a == arr[1] && b == arr[2]) {
System.out.println("你赢了");
} else if (a == arr[2] && b == arr[0]) {
System.out.println("你赢了");
} else {
System.out.println("我赢了");
}
}else{
System.out.println("平了");
}
}
}
第三种
package FUXI03;
import java.util.Random;
public class FUXI01 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Random r = new Random();
int num1 = r.nextInt(8) + 1;
if (num1 >= 1 && num1 <= 3) {
System.out.println("石头");
} else if (num1 >= 4 && num1 <= 6) {
System.out.println("剪刀");
} else if(num1 >= 7 && num1 <= 9) {
System.out.println("布");
}
System.out.println("我出");
int num2 = r.nextInt(8) + 1;
if (num2 >= 1 && num2 <= 3) {
System.out.println("石头");
} else if (num2 >= 4 && num2 <= 6) {
System.out.println("剪刀");
} else if(num2 >= 7 && num2<= 9){
System.out.println("布");
}
if (num1 >= 1 && num1 <= 3 && num2 >= 1 && num2 <= 3) {
System.out.println("我们平了");
} else if (num1 >= 1 && num1 <= 3 && num2 >= 4 && num2 <= 6) {
System.out.println("你赢了");
} else if(num1 >= 1 && num1 <= 3 && num2 >= 7 && num2 <= 9){
System.out.println("我赢了");
}
if (num1 >= 4 && num1 <= 6 && num2 >= 4 && num2 <= 6) {
System.out.println("我们平了");
} else if (num1 >= 4 && num1 <= 6 && num2 >= 1 && num2 <= 3) {
System.out.println("我赢了");
} else if(num1 >= 4 && num1 <= 6 && num2 >= 7 && num2 <= 9){
System.out.println("你赢了");
}
if (num1 >= 7 && num1 <= 9&& num2 >= 7 && num2<= 9) {
System.out.println("我们平了");
} else if (num1 >= 7 && num1 <= 9&&num2 >= 4 && num2 <= 6) {
System.out.println("我赢了");
} else if(num1 >= 7 && num1 <= 9&&num2 >= 1 && num2 <= 3) {
System.out.println("你赢了");
}
}
}
第四种
package 石头剪刀布;
import java.util.Random;
import java.util.regex.Pattern;
public class sjb {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Random r = new Random();
int x = r.nextInt(8);
String[] arr = { "你出 \r\n 石头 \r\n我出\r\n布\r\n我赢了", "你出 \r\n石头 \r\n我出\r\n剪刀\r\n你赢了", "你出\r\n石头 \r\n我出\r\n石头\r\n平了","你出 \r\n 剪刀 \r\n我出\r\n石头\r\n我赢了","你出\r\n剪刀 \r\n我出\r\n布\r\n你赢了","你出\r\n剪刀 \r\n我出\r\n剪刀\r\n平了","你出 \r\n 布 \r\n我出\r\n剪刀\r\n我赢了", "你出 \r\n 布 \r\n我出\r\n石头\r\n你赢了","你出 \r\n布 \r\n我出\r\n布\r\n平了"};
System.out.println(arr[x]);
}
}
|
|