Computer Science, asked by vasuhunk419, 1 year ago

What will be the output of the following Java code snippet? Test(int x) switch (x % 2) case 0: System.out.print("Odd"); break; case 1: System.out.print("Even"); break; Test n = new Test(2); a. Odd b. Even c. Error d. OddEven

Answers

Answered by BadGuy
0

Hey buddy

_______________


C. It's error because for odd even program this logic will not gonna work on any platforms doesn't matter it's Java or not it should be (x %2 ==0) this type of error is known as logical error


Hope it helps you

Answered by topanswers
0

Given:

Test(int x)  

switch (x % 2)  

case 0: System.out.print("Odd");

break;  

case 1: System.out.print("Even");  

break;

To find:

Test n = new Test(2);  

Solution:

As the cases passes 2,

The ( x % 2 ) returns the remainder of the integer x.

Hence,

2 % 2 = 0

So, it enters case 0.

Case 0 functions by printing ( "Odd" )

The program prints "Odd" as it enters in the switch case 0.

Hence, ( a ) Odd is the answer.

Read more on Brainly. in - https://brainly.in/question/6586154

Similar questions