【发布时间】:2017-01-17 07:25:04
【问题描述】:
我在将程序加载到 linux 服务器时遇到问题。我能够从我正在使用的 IDE 中复制粘贴我的代码,并让服务器编译并运行代码,但执行为空。我将行 println 更改为 printf 并且文件将无法编译并且每次都给我错误“无法找到或加载主类 Program01”。包括当我粘贴刚刚工作的旧代码时,我正在尝试的一切都失败了。寻找关于我可以解决的其他意见。它从编号为“312032486”的输入文件中提取。只是想知道为什么它无法找到或加载主类。我相信其他一切都按预期工作。
感谢所有查看并打开任何设备的人,因为我是 java 新手。
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package program01;
import java.util.Scanner;
/**
*
* @author Devin
*/
public class Program01 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
// Create variables for birth rate, death rate and immigration raet
int birthRate = 1 / 7;
int deathRate = 1 / 13;
int immigrationRate = 1 / 45;
// Variable creating the number of seconds per year
int secondsPerYear = 60 * 60 * 24 * 365;
// Variable to find births, deaths and immigrants added per year
int birthsPerYear = birthRate * secondsPerYear;
int deathsPerYear = deathRate * secondsPerYear;
int immigrantsPerYear = immigrationRate * secondsPerYear;
// Scanner method to GET population through input.data
Scanner sc = new Scanner (System.in);
System.out.printf("Enter population: ");
int population = sc.nextInt();
System.out.printf("Population is: " + population);
// Math to create variables for population per X year
double populationYear0 = population;
double populationYear1 = populationYear0 + birthsPerYear - deathsPerYear + immigrantsPerYear;
double populationYear2 = populationYear1 + birthsPerYear - deathsPerYear + immigrantsPerYear;
double populationYear3 = populationYear2 + birthsPerYear - deathsPerYear + immigrantsPerYear;
double populationYear4 = populationYear3 + birthsPerYear - deathsPerYear + immigrantsPerYear;
double populationYear5 = populationYear4 + birthsPerYear - deathsPerYear + immigrantsPerYear;
// Print out the variables data from code above
System.out.println("Population Year 0: " + populationYear0);
System.out.println("Population Year 1: " + populationYear1);
System.out.println("Population Year 2: " + populationYear2);
System.out.println("Population Year 3: " + populationYear3);
System.out.println("Population Year 4: " + populationYear4);
System.out.println("Population Year 5: " + populationYear5);
}
}
【问题讨论】:
-
你执行的命令是什么?
-
使用我学校的 linux 服务器,使用名为 SubmitJ 的命令。然后它让我选择主类,当我选择这个程序时,Program01 它给了我错误。我的其他 2 个主课程序运行良好。
-
他们也有包吗?你编译成
jar还是classes?服务器是指在线法官吗? -
@Devin 你能附加另一个你成功部署在服务器上的应用程序吗?
-
这是我通过 PUTTY 使用 linux 服务器看到的链接。 HelloWorld.Java 和 JavaApplication1.java 都可以完美执行,但 Program01 没有。 gyazo.com/9ca6402b71ee70377a813bad0c899b3b
标签: java