首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java编程-纸岩剪刀的入门器

Java编程-纸岩剪刀的入门器
EN

Stack Overflow用户
提问于 2016-04-08 04:33:56
回答 2查看 560关注 0票数 0

如果可能的话需要一些指导。对爪哇来说是新手。不知道为什么下面的代码石头,纸,剪刀游戏不起作用。欢迎您提出任何建议或建议。我知道在这个伟大的论坛上有很多例子--但我仍然掌握着基本知识。谢谢。

代码语言:javascript
复制
import java.util.*;         
import java.util.Scanner;   
import java.util.Random;     
public class Game       
{                           
    public static void main (String[] args){     

        int NumberofRoundsPlayed;        
        int NumberofRoundsWonbyHuman = 0;   

        Scanner Keyboard = new Scanner (System.in       

        System.out.println("DO YOU WANT TO PLAY ROCK PAPER SCISSORS- Y/N");                       
        String HumanPlaying  = Keyboard.nextLine();


        if(HumanPlaying ==("No"))
        {
            System.out.println("Game Over");
            System.exit(0);}
        }       

    int Paper = 1;  
    int Scissor = 2;    
    int Rock  = 3;      

    int HumanSelection;
    int humanroundsWon =0;

    System.out.println("HOW MANY ROUNDS DO YOU WANT TO PLAY");
    NumberofRoundsPlayed = Keyboard.nextInt();      

    while  (NumberofRoundsPlayed <= NumberofRoundsPlayed +1)  
    {
        Scanner Computer = new Scanner (System.in);
        Random rand = new Random();

        int ComputerChoice =Computer.nextInt(3)+1; 
        System.out.println(ComputerChoice);

      System.out.println("Select 1 for Paper, 2 for Scissor or 3 for Rock");                    
        HumanSelection = Keyboard.nextInt();

        //SEE WHO WINS

        If (ComputerChoice== 1)
        {
            If (HumanSelection==1)
            {
            System.out.println("Computer and Human Have Tied");
            }   Else if (HumanSelection==2)
            {
                System.out.println("Person Wins");
                humanroundsWon == humanroundsWon+1;
            }
            Else if (HumanSelection==3)
            {
                System.out.println("Computer Wins");
            }

        Else if (ComputerChoice==2)
        {
            If (HumanSelection==1)
            {
                System.out.println("computer Wins");

            }
            Else if (HumanSelection==2)
            {
            System.out.println("Computer and Person Have Tied");
            }
            Else if (HumanSelection==3)
            {
                System.out.println("Person Wins");
                humanroundsWon == humanroundsWon+1;

            }
        }

        Else if (ComputerChoice==3)
        {

    }
            If (HumanSelection==1)
            {
                System.out.println("Person Wins");
                humanroundsWon == humanroundsWon+1;
            }

        Else if (HumanSelection==2)
        {
            {       System.out.println("Computer Wins");
            }

            Else if (HumanSelection==)
            {
                    System.out.println("Tie");  
                    roundsWon == roundsone+1;
            }
        }
        }
    }
    }
 }

        System.out.println("Game Over");
            System.exit(0);}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-04-08 05:09:51

这是代码,如果我对您的场景的理解是正确的话。当您提出问题时,请指出code实际上需要执行什么,以便其他人可以帮助您。还有一点提示,尝试使用像eclipse这样的IDE来帮助您编写代码。您可以找到它,这里只需根据您的平台架构( 32bit64bit)下载Eclipse IDE for Java EE Developers并提取zip文件。然后运行eclipse IDE --它很简单

代码语言:javascript
复制
import java.util.*;         
import java.util.Scanner;   
import java.util.Random;     
public class Game       
{                           
    public static void main (String[] args){     

        int NumberofRoundsPlayed;        
        int NumberofRoundsWonbyHuman = 0;   

        Scanner Keyboard = new Scanner (System.in);      

        System.out.println("DO YOU WANT TO PLAY ROCK PAPER SCISSORS- Y/N");                       
        String HumanPlaying  = Keyboard.nextLine();


        if(HumanPlaying.equals("No"))
        {
            System.out.println("Game Over");
            System.exit(0);
        }



        int Paper = 1;  
        int Scissor = 2;    
        int Rock  = 3;      

        int HumanSelection;
        int humanroundsWon =0;

        System.out.println("HOW MANY ROUNDS DO YOU WANT TO PLAY");
        NumberofRoundsPlayed = Keyboard.nextInt();      

        while  (NumberofRoundsPlayed < NumberofRoundsPlayed++)  
        {
            Scanner Computer = new Scanner (System.in);
            Random rand = new Random();

            int ComputerChoice =Computer.nextInt()+1; 
            System.out.println(ComputerChoice);

            System.out.println("Select 1 for Paper, 2 for Scissor or 3 for Rock");                    
            HumanSelection = Keyboard.nextInt();

            //SEE WHO WINS

            if (ComputerChoice== 1)
            {
                if (HumanSelection==1)
                {
                    System.out.println("Computer and Human Have Tied");
                }
                else if (HumanSelection==2)
                {
                    System.out.println("Person Wins");
                    humanroundsWon++;
                }
                else if (HumanSelection==3)
                {
                    System.out.println("Computer Wins");
                }
            }
                else if (ComputerChoice==2)
                {
                    if (HumanSelection==1)
                    {
                        System.out.println("computer Wins");

                    }
                    else if (HumanSelection==2)
                    {
                        System.out.println("Computer and Person Have Tied");
                    }
                    else if (HumanSelection==3)
                    {
                        System.out.println("Person Wins");
                        humanroundsWon++;

                    }
                }

                else if (ComputerChoice==3)
                {


                    if (HumanSelection==1)
                    {
                        System.out.println("Person Wins");
                        humanroundsWon++;
                    }

                    else if (HumanSelection==2)
                    {
                        System.out.println("Computer Wins");
                    }

                    else if (HumanSelection==3)
                    {
                        System.out.println("Tie");  

                    }
                }

            }

        System.out.println("Game Over");
        System.exit(0);
        }
    }
票数 0
EN

Stack Overflow用户

发布于 2016-04-08 04:40:42

如果它不编译,Scanner Keyboard = new Scanner (System.in是一个不完整的语句。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36491600

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档