Question: 1. Rewrite the following if/else statement in only one line of code using conditional operator. Avoid using any white spaces in your code. if(a <5)

1. Rewrite the following if/else statement in only one line of code using conditional operator. Avoid using any white spaces in your code.

if(a<5)    b = a*10; else    b = a;

2. double x = 45678.259;
System.out.printf("???", x);

Examine code above. What formatting string must be written in place of ??? in order for the output to be

45,678.3

Avoid using any white spaces in your answer.

3. Convert the following switch statement into the "if/else if" statement below by filling in the blanks. Avoid adding any extra white spaces.

int x = keyboard.nextInt(); switch(x)  {     case 1: System.out.println("Hey!!");             break;      case 3: System.out.println("Hello!!");             break;      case 10: System.out.println("Hey!!");             break;      default: System.out.println("How are you?"); }


if( ___ )
System.out.println("Hey!!");

else if( ___ )
System.out.println("Hello!!");

else ___

4. What formatting string must replace ??? for the output below match the statements it is supposed to produce. The formatting string is the same in all 4 statements.

Statements:

System.out.printf("???", 1234); System.out.printf("???", 234); System.out.printf("???", 34); System.out.printf("???", 4);

Output:

|1234| | 234| |  34| |   4|

Step by Step Solution

3.44 Rating (157 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Answer a 5 ba10 ba conditional operator 2 Answer Syst... 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 Accounting Questions!