1. Rewrite the following if/else statement in only one line of code using conditional operator. Avoid using...
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) 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|
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill