|  | 
 
 
 楼主|
发表于 2021-9-29 13:21:57
|
显示全部楼层 
| import java.util.Scanner;
 
 public class a123 {
 public static void main(String[] args) {
 while (true) {
 System.out.println("------------------猜拳小游戏------------------");
 System.out.println("|        0.结束游戏 1.剪刀 2.石头 3.布        |");
 System.out.println("|                .\"\".    .\"\",               |");
 System.out.println("|                |  |   /  /                |");
 System.out.println("|                |  |  /  /                 |");
 System.out.println("|                |  | /  /                  |");
 System.out.println("|                |  |/  ;-._                |");
 System.out.println("|                |  ` _/  / ;               |");
 System.out.println("|                |  /` ) /  /               |");
 System.out.println("|                | /  /_/\\_/\\               |");
 System.out.println("|                |/  /      |               |");
 System.out.println("|                (  ' \\ '-  |               |");
 System.out.println("|                 \\    `.  /                |");
 System.out.println("|                  |      |                 |");
 System.out.println("|                  |      |                 |");
 System.out.println("---------------------------------------------");
 Scanner sc = new Scanner(System.in);
 int playerInt = sc.nextInt();
 int computerInt = (int) (Math.random() * 3 + 1);
 String playerStr;
 switch (playerInt) {
 case 0:
 System.out.println("退出游戏");
 return;
 case 1:
 playerStr = "剪刀";
 break;
 case 2:
 playerStr = "石头";
 break;
 case 3:
 playerStr = "布";
 break;
 default:
 System.out.println("请出正确的数字!");
 continue;
 }
 //转换电脑出拳数字为字符串 用if
 String computerStr;
 if (computerInt == 1) {
 computerStr = "剪刀";
 } else if (computerInt == 2) {
 computerStr = "石头";
 } else {
 computerStr = "布";
 }
 //判断胜负
 if ( playerInt== 1 && computerInt == 3 || playerInt == 2 && computerInt == 1 || playerInt == 3 && computerInt == 2) {
 System.out.println("你出了" + playerStr + "电脑出了" + computerStr + "胜利");
 } else if (playerInt == computerInt) {
 System.out.println("你出了" + playerStr + "电脑出了" + computerStr + "平局");
 } else {
 System.out.print("你出了" + playerStr + "电脑出了" + computerStr + "失败");
 }
 }
 }
 }
 为什么这个没有上边的问题
 
 | 
 |