File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can I do this?

 
John Chong
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class TestIO{
private static int a;
public static void main(String[] args){
System.out.println("Whats your name?");
System.in.readln(String n);
System.out.println("Hello "+n);
}
}
 
Shripad Bokil
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi John,
The code you have written will not work....instead modify your code like this...I have tested it & it works perfectly.
import java.io.*;
public class TestIO{
private static int a;
public static void main(String[] args){
try{
BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Whats your name?");
String n=reader.readLine();
System.out.println("Hello "+n);
}catch(IOException e){
System.out.println("\n Error in reading " + e);
}
}
}
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic