README.md

December 5, 2022 ยท View on GitHub

Read a string from the command line

Description

reads a string from the command line. Should be easy but it wasnt explained well so I wrote this.

More Info

text

I am using jdk 1.4 so I am not sure of compat problems ;(

Submitted On
ByChad Neal
LevelBeginner
User Rating5.0 (15 globes from 3 users)
CompatibilityJava (JDK 1.2)
CategoryInput/ Output
WorldJava
Archive File

Source Code

// 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");
	}
}