Skip to content
Snippets Groups Projects

Error fix (#1)

2 files
+ 5
4
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -38,10 +38,11 @@ public class Calc {
@@ -38,10 +38,11 @@ public class Calc {
* @throws IllegalArgumentException if n is larger than the operand count
* @throws IllegalArgumentException if n is larger than the operand count
*/
*/
public double peekOperand(int n) {
public double peekOperand(int n) {
if (n > getOperandCount()) {
int index = getOperandCount() - n - 1;
 
if (index >= getOperandCount() || index < 0) {
throw new IllegalArgumentException("Cannot peek at position " + n + " when the operand count is " + getOperandCount());
throw new IllegalArgumentException("Cannot peek at position " + n + " when the operand count is " + getOperandCount());
}
}
return operandStack.get(getOperandCount() - n - 1);
return operandStack.get(index);
}
}
/**
/**
Loading