需要exe文件才能打开控制台

问题描述

我是两个月的学生,所以请在这里忍受。

我正试图向我的朋友展示一个摇滚,纸,剪刀游戏。我已经使用launch4j成功创建了RockPaperScissors.exe。

现在,当我单击游戏的可执行文件时,将打开控制台。但是,当我的朋友尝试这样做时,如果他试图键入控制台,他会得到一个没有任何提示的控制台。

是否可以有一个可执行文件强制控制台启动?我是否需要更改代码的某些部分才能发生这种情况?

下面是代码,以防万一我需要添加一些东西来完成这项工作。

import java.util.Scanner;
import java.util.Random;

public class RockPaperScissors 
{

  /***** CONSTANT SECTION *****/

  public static void main(String[] args)
  {
    /***** DECLaraTION SECTION *****/
    Scanner keyboard;
    Random rndGen;
    char  computerChoice;
    int playerscore,compscore;
    int winner,compInt;
    String name;
    String userChoice;

    /***** INITIALIZATION SECTION *****/
    keyboard = new Scanner(system.in);
    rndGen = new Random();
    
    computerChoice = ' ';
    winner = -1;
    compInt = -1;
    
    playerscore = 0;
    compscore = 0;

    /***** INTRO SECTION *****/
    System.out.print("What is your name? ");
    name = keyboard.next();
    System.out.println("\nHi " + name + ".");
    System.out.println("\nLet's play Rock,Paper,Scissors!");
    System.out.println("Best out of 3 wins.");

    /***** INPUT SECTION *****/
    while (playerscore < 2 && compscore < 2)
    {
    System.out.print("\nEnter your choice. Type R for rock,P for paper,or S for scissors: ");
    
    
        //takes a char entry and changes it into a string,upper cases the entry,and then take the first letter of the string
    userChoice = keyboard.next();
    userChoice = userChoice.toupperCase();
    
    while (!(userChoice.equals("R") || userChoice.equals("P") || userChoice.equals("S")))
            {
        System.out.println("Invalid entry.");
        System.out.println("");
        System.out.print("Enter your choice. Type R for rock,or S for scissors: ");
        userChoice = keyboard.next();
        userChoice = userChoice.toupperCase();
            }
    
    /***** PROCESSING SECTION *****/
    
    compInt = rndGen.nextInt(3);
    
    if (compInt == 0)
      {
        computerChoice = 'R';
      }
    else if (compInt == 1)
      {
        computerChoice = 'P';
      }
    else
      {
        computerChoice = 'S';
      }

      winner = RockPaperScissors.decideWinner(userChoice,computerChoice);


    /***** OUTPUT SECTION *****/
    System.out.printf(name + " chose %s%nComputer chose %c%n",userChoice,computerChoice);
    
    switch(winner)
    {
      case 0: System.out.println("It's a tie!");
      break;
      case 1: System.out.println(name + " wins!");
      playerscore = playerscore + 1;
      break;
      case 2: System.out.println("Computer won!");
      compscore = compscore + 1;
      break;
      default: System.out.println("Invalid choice. Try again");
      break;  
    }
    System.out.println(name + ": " + playerscore + ",Computer: " + compscore);
    
    }
    if (playerscore > compscore)
    {
        System.out.println("\n" + name + " is the winner!!!");
    }
    else
    {
        System.out.println("\nSorry,the computer wins this time.");
    }
    keyboard.close();
    System.out.println("Thanks for playing!");
  }
  /***** STATIC METHODS *****/
    //Given two characters (R,P or S) determines //winner user rock paper scissors rules. Error check
  //done in main
    public static int decideWinner(String p1,char p2)
    {
    
    String combo;
    combo = String.format("%s%c",p1,p2);
    
        if ((combo.equals("RS")) || (combo.equals("PR")) || (combo.equals("SP")))
        {
            
            return 1;
        }
        else if ((combo.equals("RP")) || (combo.equals("PS")) || (combo.equals("SR")))
        {
            
            return 2;
        }
        else if ((combo.equals("PP")) || (combo.equals("SS")) || (combo.equals("RR")))
        {
      
            return 0;
        }
        else
        {
      
            return -1;
        }
        
        
    
    }
    
    
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)