Computer Science, asked by bommishettishravani, 7 months ago

COMMAND LINE ARGUMENT - PRINT STRING OR INTEGER
Command Line Argument - Print String
Integer
Write a program to accept an integer or string as
command line argument and print whether the given
input is string or integer
Sample Input (Command Line Argument)

Answers

Answered by chaithanyasaandeepra
0

Answer:

Explanation:

Sample Input (Command Line Argument) 1:

abc

Sample Output 1:

The given input is a string

Sample Input (Command Line Argument) 2:

5

Sample Output 2:

The given input is an integer

Answered by Shamsessa123
0

ANSWER:

java program:-

class simple

{

public static void main(String args[])

int n1,n2;

n1=args[0];

n2=Integer.parseInt(args[1]);

System.out.println("string:"+n1+" "+n2);

System.out.println("integer :"+n2);

}

output:-

>>javac simple.java

>>java simple Command 5

Explanation:

for accepting input as string use : args[0]

for integer use : Integer.parseInt(args[0])

for boolean use : Boolean.parseBoolean(args[0])

for compiling java program : type & save java progarm using .java extension then type in command prompt >>javac simple.java

for executing java program >>java simple "str"

Similar questions