Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi. I'm having trouble with a simple bit of code.

Java
answer = MyInput.readDouble();

An error reports the following: 'MyInput cannot be resolved'

I really don't know what the problem is. I'm new to Java.

I included the following code:
Java
import java.io.*;


Your help is very much appreciated.
Posted

This generally means that the code cannot recognize the class. It might be that MyInput is from another library, in which case, you need to import that library as well.
 
Share this answer
 
Comments
TorstenH. 9-Feb-12 2:19am    
MyInput is nothing at all - might be a custom class but is not part of any Java lib.
MyInput is a self made class, not part of any Java lib.

You should try one of the following:

Java
Scanner scan = new Scanner(System.in); 
String mySentence = scan.nextLine(); 

which would direct the System.in (which is the standard input -> keyboard) into a scanner which you can read from.

another version:
Java
BufferedReader oReader = new BufferedReader(new InputStreamReader(System.in));
String strRead = oReader.readLine();

...which uses a BufferedReader to hold the input for you. You can then read from it.

Both versions need some try/catch around it, eclipse will tell you and take care of that. That is needed as the operation can fail and your code would not be valid if the operation fails.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900