Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

Answer a 5 ba10 ba conditional operator 2 Answer Syst... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

Students also viewed these Accounting questions