So,
the question is basic. In the code below, when I pass command line argument as java CommandLineDemo 3 5 *
the file names in my current directory are being listed. Doing some research in Google I found out we should supply *
as '*'
in command line.
My question is, how can my code be modified so that it accepts '*'
in command line and performs product of operand1
and operand2
class CommandLineDemo {
public static void main(String[] args) {
int operand1 = Integer.parseInt(args[0]);
int operand2 = Integer.parseInt(args[1]);
char theOperator = args[2].charAt(0);
System.out.print(args[0] + args[2] + args[1] + " = ");
switch(theOperator) {
case ('+'):
System.out.println(operand1 + operand2); break;
case ('-'):
System.out.println(operand1 - operand2); break;
case ('*'):
System.out.println(operand1 * operand2); break;
case ('/'):
System.out.println(operand1 / operand2); break;
default:
System.out.println("Invalid Operator selected");
}
}
}