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

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 Databases Questions!