gpt4 book ai didi

java - 无法运行我的程序

转载 作者:行者123 更新时间:2023-12-02 07:49:33 25 4
gpt4 key购买 nike

尝试制作我的第一个程序“基本智力游戏”。

每次我尝试运行它时都没有显示任何内容,并且不知道出了什么问题。

希望您能给我一些帮助或建议。

顺便说一句,我在 Java 编程方面几乎是菜鸟,所以请轻松地评论:)

这是代码:

import java.util.*;
import java.util.Scanner.*;
import java.util.ArrayList.*;


public class Main {
public static void start() {

int answer = (int) (Math.random() * 1000 + 1) ;
int tries = 0 ;
int player ;
String name = "name" ;
String quit = "quit";
String y = "yes";
String n = "no";
String guess = ("player") ;
String another = ("Y") ;
Scanner input = new Scanner (System.in);


System.out.println( " Welcome to Guessing Game " ) ;
System.out.print("Please enter a number between 1 and 1000 : ");
player = input.nextInt();
long startTime = System.currentTimeMillis();
int currentGuess = -1;



while(another.equalsIgnoreCase("y")) {


do
{


if (guess.equalsIgnoreCase(quit))
{
System.out.println("Leaving Us So Soon?");
System.exit(0);
}

try {
currentGuess = Integer.parseInt(guess);
} catch (NumberFormatException nfe)
{
System.out.println("Stupid Guess I Wont Count That.");
player = input.nextInt();
tries++;

}


if (currentGuess < answer )
{
System.out.println("too low");
player = input.nextInt();
tries++;
}


else if(currentGuess > answer )
{
System.out.println("too high");
player = input.nextInt();
tries++;
}
//if the guess is invalid
if (currentGuess < 0 || currentGuess > 1000)
{
System.out.println("Stupid Guess I Wont Count That.");
player = input.nextInt();
tries++;
}
else if (currentGuess == answer)
{
//stop stop watch
long endTime = System.currentTimeMillis();
//calculate game time
long gameTime = endTime - startTime;
System.out.println("You Rock Dude, Good Job!");

System.out.println("You guessed " + tries + " times in " + (int)(gameTime/1000) + " seconds.");
System.out.println("Please enter your name.");
name = input.nextLine();
}

} while (player != answer);

Scanner playGame = new Scanner(System.in);
System.out.print("Want to go again?(y/n).....");
another = playGame.nextLine();


}
}

public static void main(String[] args) {

}
}

最佳答案

您的主要方法是空的。

main 方法包含应用程序启动时运行的代码。如果 main 方法为空,则运行应用程序时不会发生任何事情。

关于java - 无法运行我的程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3876454/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com