Java Can';我不能运行我的程序

Java Can';我不能运行我的程序,java,Java,试图让我的第一个程序成为“一个基本的思维游戏” 每次我试着运行它时,什么都没有出现,也不知道出了什么问题 希望你能给我一些帮助或建议 顺便说一句,我对Java编程非常在行,所以请不要太在意我的评论:) 代码如下: import java.util.*; import java.util.Scanner.*; import java.util.ArrayList.*; public class Main { public static void start() { int answer

试图让我的第一个程序成为“一个基本的思维游戏”

每次我试着运行它时,什么都没有出现,也不知道出了什么问题

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

顺便说一句,我对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) {

    }
}
import java.util.*;
导入java.util.Scanner.*;
导入java.util.ArrayList.*;
公共班机{
公共静态void start(){
int答案=(int)(Math.random()*1000+1);
int=0;
国际球员;
String name=“name”;
String quit=“退出”;
字符串y=“是”;
字符串n=“否”;
字符串猜测=(“播放器”);
字符串另一个=(“Y”);
扫描仪输入=新扫描仪(System.in);
System.out.println(“欢迎来到猜谜游戏”);
System.out.print(“请输入一个介于1和1000之间的数字:”);
player=input.nextInt();
long startTime=System.currentTimeMillis();
int currentGuess=-1;
while(另一个.equalsIgnoreCase(“y”)){
做
{
if(猜测.相等信号情况(退出))
{
System.out.println(“这么快就离开我们了?”;
系统出口(0);
}
试一试{
currentGuess=Integer.parseInt(猜测);
}捕获(NumberFormatException nfe)
{
System.out.println(“愚蠢的猜测,我不会数一数。”);
player=input.nextInt();
尝试++;
}
如果(当前猜测<答案)
{
System.out.println(“过低”);
player=input.nextInt();
尝试++;
}
else if(当前猜测>答案)
{
System.out.println(“过高”);
player=input.nextInt();
尝试++;
}
//如果猜测无效
如果(currentGuess<0 | | currentGuess>1000)
{
System.out.println(“愚蠢的猜测,我不会数一数。”);
player=input.nextInt();
尝试++;
}
else if(currentGuess==答案)
{
//秒表
long-endTime=System.currentTimeMillis();
//计算比赛时间
长游戏时间=结束时间-开始时间;
System.out.println(“你这个摇滚小子,干得好!”);
println(“你在“+(int)(游戏时间/1000)+“秒”中猜到了“+尝试次数+”);
System.out.println(“请输入您的姓名”);
name=input.nextLine();
}
}while(player!=回答);
扫描器游戏=新扫描器(System.in);
System.out.print(“想再去吗?(y/n)…”;
另一个=playGame.nextLine();
}
}
公共静态void main(字符串[]args){
}
}

您的主方法为空


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

如果这不是一个巨魔,我会感到震惊。没有显示的原因是因为在您的

static void main
方法您没有任何可供程序执行的代码。

Java的主方法是
main
。因此,您必须从
main
运行代码:

public static void main(String[] args) {
    start();
}

听起来像是家庭作业,不过这应该可以做到

public static void main(String[] args) {
    Main.start();
    }

做出改变,看看是否更好。

在“public class Main{”行之后,放上“start();”然后继续编写代码。

我认为只要一个问号就可以更好地传达信息。我还认为,在标题中描述这个问题会更好地传达信息。这应该教会您以增量方式实现和测试程序。如果不运行一次,您不应该生成这么多代码(即使它在一开始只是打印“欢迎来到猜谜游戏”)。将测试留给实现了大部分代码的人会使调试变得非常困难。他不需要添加Main,因为他目前在该类中。-1.即使使用类名,它也应该是“Main.start();”而不是“Main.start();”爬山者104,谢谢你的帮助,看起来我有很多东西要学真的吗?-1个打字错误?本杰明,很高兴它帮了我的忙!
public static void main(String[] args) 
{
    start();
}