Leon Held
Leon Held

Reputation: 39

No error displayed in console, simple counting program won't work

So, I am learning Java coming from Python and Scheme, and when I tried to run this simple piece of code it won't give me any type of error log, or anything at all. I don't fully understand about classes and such, so this may be the problem.

Can someone explain what's is happening, why, and how to fix it?

class midnight {
    public static void main(String[] args){
        int hour, minute, seconds, tomidnight, total;
        hour = 1;   
        minute = 45;
        seconds = 42;
        total = 86400;
        tomidnight = (((hour*3600)+(minute*60)+seconds) - total);
        System.out.println(tomidnight);

    }
}

Upvotes: 1

Views: 57

Answers (2)

JUAN CALVOPINA M
JUAN CALVOPINA M

Reputation: 3974

You can add some additional info in the printout, for example:

System.out.println("Tomidnight: " + tomidnight);

If you run the class from the terminal you must first compile with the following command:

javac midnight.java

And to execute the class, use the following command:

java midnight

This is the output: Tomidnight: -80058

Upvotes: 1

Sachin Varma
Sachin Varma

Reputation: 11

It shows -80058 in cmd because if you do this calculation in calculator then also you will get this number only. It just because of calculation and nothing else.

Upvotes: 1

Related Questions