- 代码块整个实现了简单人机猜拳功能,代码如下,实现效果如图。
package guess; import java.util.Scanner; public class guess_2 { public static void main(String[] args) { System.out.println("----猜拳游戏开始----"); System.out.println("请按要求输入:1.石头 2.剪刀 3.布"); String marks="石头"; String marks2="石头"; while(true){ Scanner in=new Scanner(System.in); int person=in.nextInt(); int computer=(int)(Math.random()*3+1); switch(person){ case 1: marks="石头"; break; case 2: marks="剪刀"; break; case 3: marks="布"; break; } switch(computer){ case 1: marks2="石头"; break; case 2: marks2="剪刀"; break; case 3: marks2="布"; break; } if(computer==person){ System.out.println("您出的是"+marks+"\n电脑出的是"+marks2+"
JAVA语言实现人机猜拳小游戏
最新推荐文章于 2021-07-22 15:11:44 发布