MULTIPLE CHOICE (java programing). 8) What is the result of 45 / 4? 8) A) 11 B)
ID: 3818374 • Letter: M
Question
MULTIPLE CHOICE (java programing).
8) What is the result of 45 / 4?
8)
A) 11 B) 10 C) 11.25 D) 12
9) The statement System.out.printf("%10s", 123456) outputs ________. (Note: * represents a space) 9) A) 12345***** B) 23456***** C) 123456**** D) ****123456 10) What is the printout of the following switch statement? char ch = 'b'; switch (ch) { case 'a': System.out.print(ch); case 'b': System.out.print(ch); case 'c': System.out.print(ch); case 'd': System.out.print(ch); }
10) A) b B) bb C) bcd D) abcd E) bbb 11) Which of the following are valid specifiers for the printf statement? (Choose all that apply.)
11) A) %10b B) %8.2d C) %4c D) %10.2e E) %6d 12) The statement System.out.printf("%5d", 123456) outputs ________.
12) A) 23456 B) 123456 C) 12345.6 D) 12345
13) Suppose x=10 and y=10 what is x after evaluating the expression (y >= 10) || (x++> 10)? 13) A) 10 B) 9 C) 11 2
14)
How many times will the following code print "Welcome to Java"? int count= 0; do { System.out.println("Welcome to Java"); } while (++count< 10); 14) A) 11 B) 8 C) 0 D) 9 E) 10
15)
What is sum after the following loop terminates? int sum = 0; int item= 0; do { item++; sum += item; if (sum > 4) break; } while (item < 5); 15) A) 6 B) 8 C) 7 D) 5 16) Do the following two statements in (I) and (II) result in the same value in sum? (I): for (int i= 0; i<10; ++i) { sum += i; } (II): for (int i= 0; i<10; i++) { sum += i; } 16) A) Yes B) No
Explanation / Answer
8. The answer is A) 11
Explanation: 45 / 4 is an integer division, which results in 11.
9. The answer is D)****123456
Explanation : %10s means right justification, since the string 123456 has 6 characters in it , there will be four leading spaces as 6+4 makes 10.
10. The answer is E)bbb
Explanation : The break statements are necessary in every case because without them, statements in switch block fall through. All statements after matching case label are executed in sequence, regardless of the expression of subsequent case labels, until a break stement is encountered.
11. The answer is , the valid specifiers for printf statements are
A) %10b format specifier for boolean values
C) %4c - format specifier for characters
D) %10.2e - format specifier for floating point number in expnential notation
E) %6d - format specifier for decimal values
Note : B)%8.2d is invalid becuse integer does not have fraction values
12. The answer is B) 123456
Explanation: If the integer has more digits than the specifier , it ignores the number in the specifier and prints the actual number.
13. The correct answer is C)11
Explanation : x++ is the post increment operator, so after the avaluation of the given expression the value of x is incremented by 1. first value of x was 10, after the expression evaluation value of x is incremented by 1, thus x becomes equal to 11.
14. Thw answer is E) 10
Explanation: The do..while loop is executed once before checking the condition, then count is incremented to 1 and conidion (count<10) is checked. This condition is true 9 times. Thus 9 +1=10. So the loop gets executed 10 times resulting in displaying "Welcome to Java" message 10 times.
15. The answer is A) 6
Explanation: Initially item = 0 ans sum = 0; then in the loop item becomes 1 and sum also becomes 1. It then checks for the condion whether sum>4, it is not, so it reaches while condition and checks it item is less than 5, yes, so the loop continues, item become 2 and sum becomes 3, if condition is false but while condition is true, so once again loop continues, item becomes 3 and sum becomes 6, here if condition is true as 6>4 and break is excuted, thus the loop is exited.
(I) and (II) Yes, they result in the same value in sum i.e. (0+1+2+3+4+5+6+7+8+9) as the preincrement(++i) and postincrement(i++) , increments i by 1 for every iteration of for loop.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.