// 1.首先提醒 输入1.石头 2.剪刀 3.布 // 然后系统随机生成123(1代表石头,2代表剪刀,3代表布) // 然后判断是玩家胜利还是系统胜利 // 如果玩家胜利,说一句,你真棒 // 系统胜利说一句,太菜了小菜鸟
import java.util.Random; import java.util.Scanner; public class test {
public static void main(String[] args) { new test().test1(); } public void test1(){ Scanner s = new Scanner(System.in); System.out.println("请输入1-3任意一个数:"); int p = s.nextInt();//用户输入 if(p > 3||p < 1){ System.out.println("捶你信不信!重来!输入1-3任意一个数:"); test1(); } System.out.println(test.people(p));//调用方法 Random ran = new Random(); int num = ran.nextInt(3)+1;//系统随机了一个数字 System.out.println(test.computer(num));//调用方法 int a = p - num ; switch (a) { case -1: case 2: System.out.println("你真棒!"); break; case 0: System.out.println("真巧!我们一样!"); break; default: System.out.println("太菜了小菜鸟!"); break; } test1(); } public static String computer(int num){ String s1=""; switch (num) {//将电脑输入的 随机数 转换成对应 文字 case 1: s1 = "电脑出:石头"; break; case 2: s1 ="电脑出:剪刀"; break; case 3: s1 ="电脑出:布"; break; } return s1; } public static String people(int p){ String s1 = ""; switch (p) {//将用户输入的 随机数 转换成对应 文字 case 1: s1 ="你出:石头"; break; case 2: s1 ="你出:剪刀"; break; case 3: s1 ="你出:布"; break; default: break; } return s1; }