Java Quiz 2 - Expressions & Variables

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

4. What is the result of the following expression? 25 / 4 + 4 * 10 % 3 a. 19 b. 7.25 c. 3 d. 7

ANS: D

1. What is the output of the following code? String username = "Tom"; int userAge = 22; System.out.print(userAge); System.out.print("\nis "); System.out.print(username); System.out.println("'s age."); a. 22 is Tom's age. b. 22 is Tom's age. c. 22 \nis Tom's age. d. 22 \n is Tom's age.

ANS: B

12. What is the value of i after the following statement is executed? int i = '2' + '3'; a. 5 b. 101 c. will not compile d. none of these

ANS: B

13. What is the value of i after the following statement is executed? int j = 2 + 'a'; a. 2 b. 99 c. will not compile d. none of these

ANS: B

14. What will be the output of the following code? char ch = 'a'; System.out.print(++ch); a. a b. b c. will not compile d. none of these

ANS: B

15. What is the value of the cityState string after this statement is executed? String cityState = "Milwaukee"; cityState = cityState + "," + "Wisconsin"; a. Milwaukee","Wisconsin c. MilwaukeeWisconsin b. Milwaukee,Wisconsin d. Wisconsin

ANS: B

2. What is the output of the following code? String username = "Tom"; int userAge = 22; System.out.println(userAge + "\nis " + username + "'s age."); a. 22 is Tom's age. b. 22 is Tom's age. c. 22 \nis Tom's age. d. 22 \n is Tom's age.

ANS: B

3. What is the result of the following expression? 10 + 5 * 3 - 20 a. -5 b. 5 c. 25 d. -50

ANS: B

5. What is the result of the following expression? 25.0 / 4 + 4 * 10 % 3 a. 19 b. 7.25 c. 3 d. 7

ANS: B

6. What is the output of the following code? int a=5, b=2, c=10; c = c + a * b - 5; a. -45 c. 25 b. 15 d. None of the above

ANS: B

10. What will be displayed as a result of executing the following code? int x = 5, y = 20; x += 32; y /= 4; System.out.println("x = " + x + ", y = " + y); a. x = 32, y = 4 b. x = 9, y = 52 c. x = 37, y = 5 d. x = 160, y = 80

ANS: C

8. Which statement is equivalent to the following statement? total = total + tax; a. total = tax++; c. total += tax; b. total = ++tax; d. total =+ tax;

ANS: C

9. Which statement is equivalent to the following statement? tax = tax + 1; a. tax++; c. Both a and b b. tax += 1; d. None of these

ANS: C

11. What will be the value of z as a result of executing the following code? int x = 5, y = 28; float z; z = (y / x); a. 5.60 b. 5.6 c. 3.0 d. 5.0

ANS: D

16. What is the value of the cityState string after these statements are executed? String cityState = "Milwaukee"; cityState = cityState + ","; cityState = "Wisconsin"; a. Milwaukee, Wisconsin c. MilwaukeeWisconsin b. Milwaukee,Wisconsin d. Wisconsin

ANS: D

17. What do each of the following expressions evaluate to given the declaration: int a = 4, b = 3, n = 4; String ans = "Y"; a. 1 <= 1 b. 1 < 1 c. false == (1 < 1) d. true == (1 < 1) e. (a+b) < 2*a f. (n > 2) && (n < 6) g. (n > 2) || (n == 6) h. !(n < 6) (False) i. (ans = = "Y") || (ans = = "y") j. (ans = = "Y") && (ans = = "y") k. (n = = 2) && (n= =7) || (ans = = "Y") l. (n = = 2) && ((n= =7) || (ans = ="Y"))

a. 1 <= 1 (True) b. 1 < 1 (False) c. false == (1 < 1) (True) d. true == (1 < 1) (False) e. (a+b) < 2*a (True) f. (n > 2) && (n < 6) (True) g. (n > 2) || (n == 6) (True) h. !(n < 6) (False) i. (ans = = "Y") || (ans = = "y") (True) j. (ans = = "Y") && (ans = = "y") (False) k. (n = = 2) && (n= =7) || (ans = = "Y") (True) l. (n = = 2) && ((n= =7) || (ans = ="Y")) (False)

7. What is the value of z after the following statements are executed? double x = 2.5, y = 4.0; int z = (int) x + y; a. 6 c. 6.5 b. 6.0 d. 7

ANS: A


Kaugnay na mga set ng pag-aaral

Biology, The Cell. Prokaryotes and Eukaryotes

View Set

TAT/ALC Physical Science Module 13 (Apologia)

View Set

008 - C11.2.2 File Extension Facts

View Set