reads a string from the command line. Should be easy but it wasnt explained well so I wrote this.
text
I am using jdk 1.4 so I am not sure of compat problems ;(
Submitted On | |
By | Chad Neal |
Level | Beginner |
User Rating | 5.0 (15 globes from 3 users) |
Compatibility | Java (JDK 1.2) |
Category | Input/ Output |
World | Java |
Archive File |
// hello <string>
import java.io.*;
public class hello
{
public static void main(String[] args)
{
//setup global vars (bad)
String userName = null;
//setup input buffer
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//do my stuff
System.out.print("\nWhats your name?\n\n");
//make sure to cath errors (they happen often with this ;( )
try
{
userName = br.readLine();
}
catch (IOException ioerror)
{
System.out.println("IO error trying to read your name!");
System.exit(1);
}
System.out.print("\n\n\nHello " + userName + "!!!\n\n\n");
}
}