Skip to content

Planet-Source-Code/chad-neal-read-a-string-from-the-command-line__2-2431

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

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
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

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published