Chapter 3 – Selections –
Unlock all answers in this set
Unlock answersquestion
Create a math program that generates to random numbers to be added together .
answer
This shows how the use of boolean or true/false is used in the answer
question
What is the code to generate a random number between 0-9?
answer
int math=(int)(Math.random() *10); System.out.print(math)
question
If 1 of the operands of an && is false then the expression is _____?
answer
false--- this is also known as the short-circuit AND operator
question
If 1 of the operands of an || is false then the expression is _____?
answer
true -- this is also known as the short-circuit OR operator
question
What is a conditional expression ?
answer
evaluates a condition based on an expression
question
What is the result of the conditional expression above?
answer
Result is the conditional expression is EXPRESSION1 if BOOLEAN-EXPRESSION is true; otherwise the result is EXPRESSION2
question
Suppose that, when you run the following program, you enter input 2 3 6 from the console. What is the output? public class Test { public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); double x = input.nextDouble(); double y = input.nextDouble(); double z = input.nextDouble(); System.out.println((x < y && y < z) ? "sorted" : "not sorted");
answer
Sorted
question
What is the format of System.out.printf("%3d#%2s#%3.2fn", 1234, "Java", 51.6653);
answer
displays 1234#Java#51.67