What is y after the following statement is executed? x = -1; y = (x < 0) ? -2 : 3; a. -3 b. -2 с. 3 d. e. Illegal expression 12. What is the output of the following code? boolean even = false; System.out.printIn((even ? "true" : "false")); a. true b. false c. nothing d. true false

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter4: Selection Structures
Section4.2: The If-else Statement
Problem 4E
icon
Related questions
icon
Concept explainers
Question

Answer 10 to 12

11. What is y after the following statement is executed?
x = -1;
y = (x < 0) ? -2 : 3;
а.
-3
b.
-2
с.
3
d.
e. Illegal expression
12. What is the output of the following code?
boolean even = false;
System.out.println((even ? "true" : "false"));
a. true
b. false
c. nothing
d. true false
13. What is Math.floor(3.6)?
а.
3.0
b.
3
с.
4
d.
5.0
14. Which of the following assignment statements is correct?
char c = 'dn';
char c = 100;
char c = 'm';
a.
b.
с.
d.
char c = "100";
15. Which of the following are valid identifiers?
a.
$failure
b.
public
с.
988ht
d.
8=9
е.
radius
Transcribed Image Text:11. What is y after the following statement is executed? x = -1; y = (x < 0) ? -2 : 3; а. -3 b. -2 с. 3 d. e. Illegal expression 12. What is the output of the following code? boolean even = false; System.out.println((even ? "true" : "false")); a. true b. false c. nothing d. true false 13. What is Math.floor(3.6)? а. 3.0 b. 3 с. 4 d. 5.0 14. Which of the following assignment statements is correct? char c = 'dn'; char c = 100; char c = 'm'; a. b. с. d. char c = "100"; 15. Which of the following are valid identifiers? a. $failure b. public с. 988ht d. 8=9 е. radius
7. To obtain the are sine of 0.5 degree, use
Math.asin(0.5)
Math.asin(Math.toDegrees(0.5))
Math.asin(Math.toRadians(0.5))
Math.sin(0.5)
a.
b.
с.
d.
8. What is the value of the following expression?
true || true && false
true
false
а.
b.
9. What is y displayed in the following code?
public class Testl {
public static void main(String[] args) {
int x = 1;
int y = x = x + 1;
System.out.println("y is " + y);
}
}
a. y is 0.
b. y is 1 because x is assigned to y first.
c. y is 2 because x + 1 is assigned to x and then x is assigned to y.
d. The program has a compile error since x is redeclared in the statement int y = x = x +1
10. Analyze the following program fragment:
int x;
double d = 1.5;
switch (d) {
case 1.0: x = 1;
case 1.5: x = 2;
case 2.0: x = 3;
Which of these is correct about the above code?
The program has a compile error because the required break statement is missing
in the switch statement.
The program has a compile error because the required default case is missing in
the switch statement.
a.
b.
с.
The switch control variable cannot be double.
d.
No errors.
Transcribed Image Text:7. To obtain the are sine of 0.5 degree, use Math.asin(0.5) Math.asin(Math.toDegrees(0.5)) Math.asin(Math.toRadians(0.5)) Math.sin(0.5) a. b. с. d. 8. What is the value of the following expression? true || true && false true false а. b. 9. What is y displayed in the following code? public class Testl { public static void main(String[] args) { int x = 1; int y = x = x + 1; System.out.println("y is " + y); } } a. y is 0. b. y is 1 because x is assigned to y first. c. y is 2 because x + 1 is assigned to x and then x is assigned to y. d. The program has a compile error since x is redeclared in the statement int y = x = x +1 10. Analyze the following program fragment: int x; double d = 1.5; switch (d) { case 1.0: x = 1; case 1.5: x = 2; case 2.0: x = 3; Which of these is correct about the above code? The program has a compile error because the required break statement is missing in the switch statement. The program has a compile error because the required default case is missing in the switch statement. a. b. с. The switch control variable cannot be double. d. No errors.
Expert Solution
Step 1

let us see the answer:-

 

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Operators
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr