CSP.AT.MASH
CSP.AT.MASH

Reputation: 113

Java Syntax Error for Temperature Conversion Program Assignment: Line 3

I wrote the following code to run in repl.it:

import java.util.Scanner;

public class Convert{
  public static void main(String [] args){
    Scanner reader = new Scanner(System.in);
    double farenheit;
    double celsius;

    System.out.print("Enter the temperature measurement in farenheit: 
");
    farenheit = reader.nextDouble();

    celsius = (farenheit - 32.0) * 5.0/9.0; 

    System.out.print("The equivalent in celsius is: ");
    System.out.println(celsius);
  }
}

I cannot get it to run unless I switch "Convert" in line three to "Main".

Why is that? I thought the syntax was public class name of program. Shouldn't that work? Do I need to use something besides repl.it, such as an IDE like BlueJ or JGRASP to do such work?

Upvotes: 0

Views: 57

Answers (1)

Sumit
Sumit

Reputation: 26

If you declare a class as public then your class name and file name must be the same.

In your case your class name is Convert which means you either have to have it in a file named Convert.java, or remove the public attribute.

Upvotes: 1

Related Questions