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

0

u/VinceGhii Jul 20 '21

Please formatte the code...

1

u/Fragrant_Baseball776 Jul 22 '21

i done the coding in word pad.

named the file Example4.java and saved under c:\java

i run cmd and go to c:\java and then run jshell and enter

javac Example4.java

i get following

Error:

';' expected

javac IfDemo.java;