Question
**using java** Given the below program with control invariant assertion. (a) What shall be written in (X) for the below program to display assertion error?
**using java**
Given the below program with control invariant assertion.
(a) What shall be written in (X) for the below program to display assertion error?
[3 marks]
(b) What shall be written in (Y) in order to complete the assertion statement?
[3 marks]
class AssertionSwitchTest {
public static void main(String[] args) {
char operator = '____(X)____';
int operand1 = 5, operand2 = 6, result = 0;
switch (operator) {
case '+': result = operand1 + operand2; break;
case '-': result = operand1 - operand2; break;
case '*': result = operand1 * operand2; break;
case '/': result = operand1 / operand2; break;
default:
assert ____(Y)____ : "Unknown operator: " + operator;
}
System.out.println(operand1 + " " + operator + " " + operand2 + " = " + result);
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started