运行编译的Java程序只是说完整

时间:2015-01-11 01:47:56

标签: java compilation

我创建了一个接受用户输入的java程序,但是在完成编译后在JGrasp中运行它只是说“操作完成”并且不允许我输入任何内容或显示我在代码中添加的任何打印文本

/*
 * The file name of your program, Assign_1.java
 *  
 * TCSS 143 – January 10th, 2015
 * Assignment 1  
 */

 import java.util.Scanner;

 /**
 * This program allows 5 town populations to be entered then converted
 * to stars based on each 1000.
 *
 * @author Thejai Riem
 * @version 1/10/15
 */

 public class Assign_1 {

   /**
   * For town1-5 variable for population # that changes later
   */

   public static int town1;
   public static int town2;
   public static int town3;
   public static int town4;
   public static int town5;

   public static void main(String[] theArgs) {
   }

   /**
   * Gets population from user input of the 5 towns.
   *
   * @param theArgs is used for user input to scanner
   */

   public static void getPopulation(String[] theArgs) {
      Scanner population = new Scanner(System.in); // Keyboard input
      System.out.println("Enter the population of town 1: ");
      town1 = population.nextInt(); // Asks input for town population
      System.out.println("Enter the population of town 2: ");
      town2 = population.nextInt(); // Changes town(#) to user input
      System.out.println("Enter the population of town 3: ");
      town3 = population.nextInt();
      System.out.println("Enter the population of town 4: ");
      town4 = population.nextInt();
      System.out.println("Enter the population of town 5: ");
      town5 = population.nextInt();
   } 

   /**
   * Draws population one * for 1000 people
   *
   * @param theArgs is used for string output
   */

   public static void drawPopulationBar(String[] theArgs) {
      System.out.println();
      System.out.println("POPULATION GRAPH:");
      System.out.println("Town 1: " + town1 / 1000);
      System.out.println("Town 2: " + town2 / 1000);
      System.out.println("Town 3: " + town3 / 1000);
      System.out.println("Town 4: " + town4 / 1000);
      System.out.println("Town 5: " + town5 / 1000);
   } 
 }

2 个答案:

答案 0 :(得分:1)

它不要求输入的原因是你永远不会路由到代码的那一部分。请注意,所有Java应用程序都通过调用main方法运行。请注意,你的是空的。我想你想要的可能是这样的:

import java.util.Scanner;

public class Assign_1 {

   /**
   * For town1-5 variable for population # that changes later
   */

   public static int town1;
   public static int town2;
   public static int town3;
   public static int town4;
   public static int town5;

   public static void main(String[] theArgs) {
       getPopulation(theArgs);
       drawPopulationBar(theArgs);
   }

   /**
   * Gets population from user input of the 5 towns.
   *
   * @param theArgs is used for user input to scanner
   */

   public static void getPopulation(String[] theArgs) {
      Scanner population = new Scanner(System.in); // Keyboard input
      System.out.println("Enter the population of town 1: ");
      town1 = population.nextInt(); // Asks input for town population
      System.out.println("Enter the population of town 2: ");
      town2 = population.nextInt(); // Changes town(#) to user input
      System.out.println("Enter the population of town 3: ");
      town3 = population.nextInt();
      System.out.println("Enter the population of town 4: ");
      town4 = population.nextInt();
      System.out.println("Enter the population of town 5: ");
      town5 = population.nextInt();
   } 

   /**
   * Draws population one * for 1000 people
   *
   * @param theArgs is used for string output
   */

   public static void drawPopulationBar(String[] theArgs) {
      System.out.println();
      System.out.println("POPULATION GRAPH:");
      System.out.println("Town 1: " + town1 / 1000);
      System.out.println("Town 2: " + town2 / 1000);
      System.out.println("Town 3: " + town3 / 1000);
      System.out.println("Town 4: " + town4 / 1000);
      System.out.println("Town 5: " + town5 / 1000);
   } 
 }

我还看到你实际上并没有使用任何命令行参数(任何命令行参数都会填充到main方法调用中的字符串数组参数中)。所以,您可以从其他两个方法中删除这些参数(但是必须将它保留在main方法中,即使它没有被使用,因为它是java期望的签名的一部分。)

答案 1 :(得分:0)

我认为这是因为你没有填写该计划的主要方法。