栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

JAVA实现石头剪刀布的游戏

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

JAVA实现石头剪刀布的游戏

 

//刚学习java,老师布置的一个比较简单的程序
//如果有任何问题可以提出讨论
import java.util.Random;
import java.util.Scanner;

public class Guess_Game {
    public static void main(String[] args) {
        String zero = "scissor.";
        String one = "rock.";
        String two = "paper.";
        Scanner sc = new Scanner(System.in);
        System.out.println("scissor (0),rock (1),paper (2): ");
        int yourGuess = sc.nextInt();
        Random random = new Random();
        int computerGuess = random.nextInt(3);
        System.out.println("The computer guess is " + computerGuess);
        if (yourGuess == computerGuess) {
            if (computerGuess == 0) {
                String str = "scissor";
                System.out.println("The computer is  " + str + "you are scissor too. It is a draw ");
                return;
            }
            if (computerGuess == 1) {
                String str = "rock";
                System.out.println("The computer is  " + str + "you are scissor too. It is a draw ");
                return;
            }
            if (computerGuess == 2) {
                String str = "paper";
                System.out.println("The computer is  " + str + "you are scissor too. It is a draw ");
                return;
            }
        }
        if (yourGuess == 0) {
            if (computerGuess == 1) {
                System.out.println("The computer is " + one + " you are " + zero + "You lost");
            }
            if (computerGuess == 2) {
                System.out.println("The computer is " + two + " you are " + zero + "You win");
            }
        }
        if(yourGuess == 1){
            if (computerGuess == 0) {
                System.out.println("The computer is " + zero + " you are " + one + "You win");
            }
            if (computerGuess == 2) {
                System.out.println("The computer is " + two + " you are " + one + "You lost");
            }
        }
        if(yourGuess == 2){
            if (computerGuess == 0) {
                System.out.println("The computer is " + zero + " you are " + two + "You lost");
            }
            if (computerGuess == 1) {
                System.out.println("The computer is " + one + " you are " + two + "You win");
            }
        }
    }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/327544.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号