Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Sending any string via cmd. code given  RSS feed

 
Shivit Agarwal
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ??
 
Jyoti Sri
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 341
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you require to read input from the console then you have to do something like



Hope that helps.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!