Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Command line input

 
KESAVAN RAMANUJAM
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

hi
Can we use command line arguments output as input to manuplicate in another set of task?
eg:
class CommandLine
{
public static void main(String args[])
{
for (int i=0;i<args.length;i++)>
System.out.println(args[i]);
}
}
when i execute this
java CommandLine 1234
output is
1234
now i want to use this output as an input to do manuplations is it possible, if so pl explain?
regards
k7
 
balakrishna
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

the command line arguements can be used as the input from the console but the point u have to remember is that the they are strings.
they have to be modified as usable form before they are used
class CommandLine
{
public static void main(String args[])
{

String s=args[0];
int i=Integer.parseInt(s);
i=i/2;
System.out.println("half of what u entered\t=\t"+i);
}
}
this requires knowledge of wraper classes.
thank u
balakrishna
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic