首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >运行编译过的Java程序就是说完成

运行编译过的Java程序就是说完成
EN

Stack Overflow用户
提问于 2015-01-11 09:47:56
回答 2查看 88关注 0票数 0

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

代码语言:javascript
复制
/*
 * 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);
   } 
 }
EN

回答 2

Stack Overflow用户

发布于 2015-01-11 09:53:11

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

代码语言:javascript
复制
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方法中,即使它没有被使用,因为它是java期望的签名的一部分)。

票数 1
EN

Stack Overflow用户

发布于 2015-01-11 09:54:18

我认为这是因为你没有填写程序的main方法。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27883181

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档