0

I made a simple java program that works on console and I have a error I never had before. There are no errors in my code but for some reason I can't run the program cause of my 'public class serie' that is never used.

this my code:

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();
        }
    }
 }
}

Thanks in advance !

5
  • 1
    Did you mean ` public static void main `? Oct 31, 2013 at 19:25
  • 2
    Do you get a message? Does it crash your machine? Does it set your house on fire? What happens that isn't supposed to happen when you run the code?
    – arcy
    Oct 31, 2013 at 19:26
  • @rcook I'm going to have nightmares about my code setting my house on fire now.
    – Cruncher
    Oct 31, 2013 at 19:30
  • @Cruncher I hope it never does, in fact I hope that never happens. But if it does and you want someone on SO to answer a question about it, be sure to put it in your question ...
    – arcy
    Oct 31, 2013 at 19:32
  • @rcook Great, you made me laugh at work.
    – Cruncher
    Oct 31, 2013 at 19:36

4 Answers 4

9

Declare your main method as static, not final. Why have you declared it final in the first place?

1
  • +1 There is not much incremental testing here (input != "y") is always true. Oct 31, 2013 at 19:27
1

Instead of final use static modifier to the main method. The main method should be static with signature allows it to be the entry point of the runnable class.

1

Your main needs to be static.

Non-static methods require the class to be instansiated and Java doesn't instantiate your class by magic.

0

Java starts running a program with the specific

public static void main(String[] args) 

signature. So your main method should be

public static void main(String[] args) 

and not

public final void main (String[] args)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.