1

I'm trying to create a simple program that converts degrees in Fahrenheit to degrees in Celcius on my mac through the Terminal application and using the vi editor.

My code is as follows:

import java.io.*; 
public class MyThirdJavaProgram
{
public static void main (String [] args)
    {
    double celcius, fahrenheit;
    fahrenheit = Console.readDouble("fahrenheit");
    celcius = convertFahrenheitToCelcius(fahrenheit);
    System.out.println("Degrees in celcius are " + celcius);
    }

private static double convertFahrenheitToCelcius (double ins)
    {
    double celcius;
    celcius = ((ins-32.0)*5.0)/9.0;
    return celcius;
    }
}

The error I keep getting is:

MyThirdJavaProgram.java:7: cannot find symbol
symbol  : method readDouble(java.lang.String)
location: class java.io.Console
fahrenheit = Console.readDouble("fahrenheit");
                    ^

What am i doing wrong here? I've tried a lot of different ways to code it such as

fahrenheit = Console.in.readDouble(fahrenheit)

and

fahrenheit = System.console.readDouble(fahrenheit)

but absolutely nothing works and the error statement is almost the same every time. I'm very new to java but this is just confusing the heck out of me. Any help that solves this dang thing would be awesome, even if you tell me to re-write half of it.

2 Answers2

1

There is no method readDouble(String) in Console API. Please use java.util.Scanner. Example Scanner.nextDouble()

Keerthivasan
  • 12,040
  • 2
  • 26
  • 49
0

You should consider using the Java class Scanner. It is much more helpful and easier. Typically, the use of this class is very widespread for "inputting" from the user. There are many references for it. You can try the following link and references :

  1. How to use Scanner Class
  2. Simple reference to Scanner

Hope it helps. :)

Community
  • 1
  • 1
user2339071
  • 4,044
  • 1
  • 25
  • 44