繁体   English   中英

无法运行我的程序

[英]Can't Run My Program

试图让我的第一个节目“基本思维游戏”。

每次我尝试运行它都没有显示出来,也不知道出了什么问题。

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

顺便说一句,我几乎是Java编程的NOOB所以请轻松评论:)

这是代码:

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方法为空,则在运行应用程序时不会发生任何事情。

如果这不是巨魔,我会被震惊。 没有出现的原因是因为在你的
static void main方法您没有任何代码来执行程序。

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

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

听起来像是家庭作业,但这应该可以解决问题。

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

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

在你的“公共类Main {”行之后,输入“start();” 然后继续你的代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM