0

我制作了一个在控制台上运行的简单 java 程序,但我遇到了以前从未遇到过的错误。我的代码中没有错误,但由于某种原因,我无法运行我从未使用过的“公共类系列”的程序。

这是我的代码:

import java.math.BigInteger;
import java.util.Scanner;

public class serie {
public final void main(String[] args) throws Exception {
    final int BASE = 36;
    final BigInteger MODULO = new BigInteger("ZV", BASE);;
    Scanner keyboard = new Scanner(System.in);
    String strChassisNummer;
    String input = "y";

    while (input == "y"){
        try{
            System.out.print("Geef een chasis nummer in:");
            strChassisNummer = keyboard.nextLine();
            BigInteger chassisNummer = new BigInteger(strChassisNummer,
                    BASE);

            BigInteger remainder = chassisNummer.remainder(MODULO);
            System.out.print(strChassisNummer);
            System.out.print(";");
            String paddedRemainder = remainder.toString(BASE);
            if (paddedRemainder.length() == 1)
            {
                System.out.print("0" + paddedRemainder.toUpperCase());
            }
            else
            {
                System.out.print(paddedRemainder.toUpperCase());
            }
            System.out.println();
            System.out.print("Wenst u nog een chasis nummer in te geven ? (y/n): ");
            input =keyboard.nextLine();

            if (input != "y"){
                break;
            }
        }
        catch (Throwable t){
            t.printStackTrace();
        }
    }
 }
}

提前致谢 !

4

4 回答 4

9

将您的主要方法声明为静态的,而不是最终的。为什么你首先宣布它是最终的?

于 2013-10-31T19:25:52.907 回答
1

而不是对方法final使用static修饰符main。该main方法应该是静态的,签名允许它成为可运行类的入口点。

于 2013-10-31T19:27:54.750 回答
1

你的主要需要是静态的。

非静态方法需要实例化类,Java 不会通过魔法实例化您的类。

于 2013-10-31T19:28:19.890 回答
0

Java 开始运行具有特定

public static void main(String[] args) 

签名。所以你的主要方法应该是

public static void main(String[] args) 

并不是

public final void main (String[] args)
于 2013-10-31T19:31:56.720 回答