Question: with this code public static int evaluate ( String expression ) { int result; String left; String right; String [ ] operands; operands = expression.split

with this code public static int evaluate(String expression){
int result;
String left;
String right;
String[] operands;
operands = expression.split("x");
result =0;
try {
left = operands[0];
right = operands[1];
} catch (ArrayIndexOutOfBoundsException aiiobe){
left ="1";
right ="1";
}
try {
result = Integer.parseInt(left)* Integer.parseInt(right);
} catch (NumberFormatException nfe){
result =0;
}
return result;
} answer this question What would be the result of invoking Version 4 of evaluate() with the parameter "3xa"?
The value 0 would be returned
The value 1 would be returned
The value 15 would be returned
A NumberFormatException would be thrown
An ArrayIndexOutOfBoundsException would be thrown

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!