VB icon

Read a string from the command line

Email
Submitted on: 1/2/2015 4:31:00 PM
By: Chad Neal (from psc cd)  
Level: Beginner
User Rating: By 3 Users
Compatibility: Java (JDK 1.2)
Views: 1645
 
     reads a string from the command line. Should be easy but it wasnt explained well so I wrote this.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: 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.
// By: Chad Neal (from psc cd)
//
// Inputs:text
//
// Returns:text
//
// Side Effects:I am using jdk 1.4 so I am not sure of compat problems ;(
//**************************************

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


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.