Question: The input to the program is an integer variable, opCode and two double variables, X and Y with values 23.45 and 19.82 respectively.Use the table

 The input to the program is an integer variable, opCode and two double variables, X and Y with values 23.45 and 19.82 respectively.Use the table to write program that, based on the value of opCode, does the necessary operation on operands X and Y and prints the result.


opCode

Operation

1

+

2

*

3

-

4

/

5

%

Anything else

Prints "Invalid choice."


4. What is the output of each of the following code fragments? Given the declarationint a=1, b=2, c=3;

a. if (6 < 2 * 5)

System.out.print("Hello");

System.out.print(" There");


b. int x = 100; int y = 200;

if (x > 100 && y <=200)

System.out.print(x+" "+y+" "+(x+y));

else

System.out.print(x+" "+y+" "+(2*x-y));

c. if(a>b)

if(a>c)

System.out.println("1111");

else

System.out.println("2222");


5. Given an integer, n = 12345. Write program using extended if statements that does the following:

If 'n' is odd, print Weird.

If 'n' is even and in the inclusive range of 2 to 5, print Not Weird.

If 'n' is even and in the inclusive range of 6 to 20, print Weird.

If 'n' is even and greater than 20, print Not Weird.

Step by Step Solution

3.33 Rating (147 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

1 Program for performing operations based on opCode Java import javautilScanner public class Calcula... View full answer

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!