它在我的电脑IDE中运行良好但是当我将此程序提交到在线IDE时,如ideone.com,它会产生运行时错误。我需要将此程序提交给codeeval.com以完成我的挑战,但又有错误:
错误:无法找到或加载主类
代码:
import java.util.Scanner;
class FizzBuzz {
public static void main(String[] args) {
int n = 1, userinput;
Scanner scan = new Scanner(System.in);
System.out.println("Enter the Number till you want to get your Fizz & Buzz series");
userinput = scan.nextInt();
while (n != userinput) {
if ((n % 3 == 0) && (n % 5 == 0)) {
System.out.println(" FizzBuzz ");
} else if (n % 3 == 0) {
System.out.println(" Fizz ");
} else if (n % 5 == 0) {
System.out.println(" Buzz ");
} else {
System.out.println(" " + n + " ");
}
n++;
}
}
}
答案 0 :(得分:-1)
"错误:找不到或加载主类Main"提示这个问题。
如果您访问ideone.com,默认代码为:
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
所以这个类需要class Ideone
或public class Main
来编译。