public class Eval {
public static void main(String[] args) {
int operand1;
char exp1;
int operand2;
if (args.length != 3 ) {
System.err.println("*** Program needs 3 arguements***");
System.err.println("Usage: java Eval int1 exp int2");
System.exit(1);
}
operand1 = Integer.parseInt(args[0]);
exp1 = args[1].charAt(0);
operand2 = Integer.parseInt(args[2]);
System.out.print(args[0] + args[1] + args[2] + "=");
switch(exp1){
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(" Error.Invalid operator.");
}
}
}
This is a program to do mathematical operations. Currently the program can do everything but multiply the integers, why does this happen? Furthermore, why is the (Usuage: java Eval) part necessary -- it doesn't work without it. Is there a way to avoid doing this? Lastly why are the args necessary. I'm sorry for so many questions, but I don't want to blindly write a program with no clear understanding of what I'm actually doing. Thank You very much for all the help and once again sorry for so many questions!