r/javahelp • • Jul 20 '21

Java Error

i have just started learning and writing a sample code to convert gallons into liters, i wrote below from a book

class Example4 {
public static void main(String args[]) {
double gallons = 10.0;
double liters=gallons*3.7854;
System.out.println("10 gallons ="+liters+"liters");
}
}

but when i do javac Example4.java. i get following error, i can't understand where did i make mistake in such a simple code

Error:

':' expected

javac Example4.java

0 Upvotes

16 comments sorted by

View all comments

Show parent comments

1

u/Fragrant_Baseball776 Jul 20 '21

i copied the code directly from Example4.java and i keep getting the error, how is that possible?

2

u/[deleted] Jul 20 '21

Example4.java...where?

-2

u/Fragrant_Baseball776 Jul 20 '21

thats my file and i use javac Example4.java to compile and get the error

i have the file at c:\java

5

u/desrtfx Out of Coffee error - System halted Jul 20 '21

Sorry, but all you tell us does not help us to identify the issue in the faintest.

You are not even telling us what learning resource you are using, what IDE, how you compile the code, etc.

As such, we cannot tell you anything other than the code that you posted here is error free and compiles just fine.

Maybe try a different tutorial. We commonly recommend the MOOC Java Programming from the University of Helsinki. It is one of the best free Java courses around.