Command Line Argument Example in Java
Write a program to get command line inputs in java
Try your Solution
Strongly recommended to Solve it on your own, Don't directly go to the solution given below.
Program or Solution
class Program
{
public static void main(String args[])
{
System.out.println(args[0]);
System.out.println(Integer.parseInt(args[1]) +1);
}
}
Output
Program Explanation
All the programs in java accepts command line input. The thing you want to know is how to use it.
String args[] argument collects inputs given in the command line while running program. you can give any number of
inputs in command line there is no restriction in size. It always read as string and can be converted to other type.
The given inputs can access from args[0] to... args[size-1]
Sample
Command to Compile Java Program: javac Program.java
Command ro run Java Program: java Program
Command line argument while run command: java Program Decode 123
Comments
Related Programs
- Java Program to Print Welcome
- Java Program to Print the given Message
- Java Program to Print the given word
- Java Program to print the given integer number
- Java Program to print the given fractional number
- Java Program to print the given fractional number in 2 digit decimal format
- Java Program to print the ASCII value of a character
- Java Program to print two numbers with a space between them
- Java Program to print two numbers with a tab space between them
- Java Program to print two numbers in two lines
- Java Program to Print the Character of given ASCII Value
- println Statement Example in Java
- Literals in Java With Example
- Print and println difference with Example
- Implicit Type Conversion Example in Java
- Explicit Type Conversion Example in Java
- Escape Sequences and Format Specifiers Example in java