How to read a string from the command line?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   shyamtanu_majumder
Posted On:   Thursday, March 21, 2002 10:24 PM

I want to read a string from the command line. How do i do it?can anyone send me a sample code?

Re: How to read a string from the command line?

Posted By:   m_muruges  
Posted On:   Friday, March 22, 2002 04:46 AM

hi,
you can get it from the String[] arg parameter in the main method.
see the following program.

class Command
{
public static void main(String arg[])
{
if (arg.length<1)
{
System.out.println("Usage: java Command name");
}
System.out.println("Your name is:"+arg[0]);
}

it will print ur name if you run the program as below

java Command majumder
About | Sitemap | Contact