JAVA 猜拳游戏三局两胜版

本文介绍了一个基于JAVA编写的猜拳游戏,实现了三局两胜的规则。详细代码展示在文章中,游戏规则来源于《JAVA程序语言设计》的相关练习题。
摘要由CSDN通过智能技术生成

代码如下

package HomeWork_1;

import java.util.Scanner;

public class PlayGame {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int winTime1 = 0, winTime2 = 0;
		while (winTime1 < 2 && winTime2 < 2) {
			System.out.print("scissor(0), rock(1), paper(2) :");
			int computer = (int) (Math.random() * 3);
			int user = in.nextInt();
			switch (computer) {
			case 0:
				System.out.print("The computer is scissor.");
				break;
			case 1:
				System.out.print("The computer is rock.");
				break;
			case 2:
				System.out.print("The computer is paper.");
				break;
			}
			System.out.print((user == 0) ? "You are scissor."
					: (user == 1) ? "You are rock."
							: (user == 2) ? "You are paper."
									: "\nInput error, please re-enter.");
			if (user == computer) {
				System.ou
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值