|
-
Jun 7th, 2006, 06:21 PM
#1
Thread Starter
Frenzied Member
exception thrown for chardata = stdin.readline();
Hello
i was wondering how this piece of code executed without any problems
import java.io.*;
public class InputToDouble
{
public static void main (String[] args) throws IOException
{
String charData;
double value;
BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in));
System.out.println("Enter a double:");
charData = stdin.readLine();
value = Double.parseDouble( charData ) ;
System.out.println("value: " + value +" twice value: " + 2*value );
}
}
whereas this piece of code
import java.io.*;
/**
*
* @author Moyeen
*/
public class mywelcome {
public static void main (String[] args)
{
String charData;
double value;
BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in));
System.out.println("Enter a double:");
charData = stdin.readLine();
value = Double.parseDouble( charData ) ;
System.out.println("value: " + value +" twice value: " + 2*value );
}
}
gives the error
mywelcome.java [21:1] unreported exception java.io.IOException; must be caught or declared to be thrown
chardata = stdin.readline();
why is the readline causing an exception?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|