Exception in thread "main" java.lang.Error: Unresolved compilation problem: [message #1835626] |
Tue, 08 December 2020 21:43  |
Eclipse User |
|
|
|
package calcengine;
public class Calcengine {
//block statements & switch statements, loops arrays//
public static void main(String[] args) {
double[] leftVals = {100.0d, 25.0d, 225.0d, 11.0d};
double[] rightVals = {50.0d, 92.0d, 17.0d, 3.0d};
char[]opCodes = {'d', 'a', 's', 'm'};
double [] results = new double [opCodes.length];
if (args.length == 0) {
for(int i = 0;i < opCodes.length; i++) {
results[i]= execute(opCodes[i], leftVals[i], rightVals[i]);
}
for(double currentResult : results)
System.out.println(currentResult);
} else if(args.length == 3)
handleCommandLine(args);
else
System.out.println("Please provide an operation code and 2 numeric values");
}
private static void handleCommandLine(String[] args) {
char opCode = args[0].charAt(0);
double leftVal = Double.parseDouble(args[1]);
double rightVal = Double.parseDouble(args[2]);
double result = execute(opCode, leftVal, rightVal);
System.out.println(result);
}
static double execute(char opCode, double leftVal, double rightVal) {
double result;
switch(opCode) {
case 'a':
result = leftVal + rightVal;
break;
case 's':
result = leftVal - rightVal;
break;
case 'm':
result = leftVal * rightVal;
break;
case 'd':
result = rightVal != 0? leftVal / rightVal : 0.0d;
break;
default:
System.out.println("Invalid opCode: " + opCode);
result =0.0d;
break;
}
return result;
}
Syntax error insert "}" to complete ClassBody -I don't know why I am seeing this error
I receive the error Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at calcengine.Calcengine.main(Calcengine.java:5)
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.08519 seconds