aspose file tools*
The moose likes Beginning Java and the fly likes Sending any string via cmd. code given Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Sending any string via cmd. code given " Watch "Sending any string via cmd. code given " New topic
Author

Sending any string via cmd. code given

Shivit Agarwal
Ranch Hand

Joined: Feb 28, 2008
Posts: 82
public class argss {
public static void main(String[] args) {
for (int i=0; i < args.length; i++) {
System.out.println("Hello " + args[i]);
}
}
}

I tried running the application but I didn't get any output ??
How to send any string via Command Prompt ??

Also how to send input in a program. Like "system.out.print" outputs on the console , how can we input to the code. Either way like In C++ we use "cin" to input in the program, how/what is for Java ??


Have the determination of mirror which never fails to reflect in spite of being broken into pieces.<br /> <br />Kiss the hands you cannot bite.<br /> <br />An Optimist is one who starts taking a bath when he accidentally falls into the water.
Jyoti Sri
Greenhorn

Joined: Mar 10, 2008
Posts: 12
For passing command line parameters , after compiling you class when you run it just say

java <classname> argument1 argument2 argument3 ...

in your case

java argss world
I am passing "world" as parameter
Shivit Agarwal
Ranch Hand

Joined: Feb 28, 2008
Posts: 82
OOPs it was same as C/C++.
Anyway Thanks a lot @Jyoti S

Also what is the alternate of cin(C++) in Java ??
Anubhav Anand
Ranch Hand

Joined: May 18, 2007
Posts: 341

If you require to read input from the console then you have to do something like



Hope that helps.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sending any string via cmd. code given