Java Test 31) How many times are the following loops executed? for (int i = 0; i
ID: 3819935 • Letter: J
Question
Java Test
31) How many times are the following loops executed? for (int i = 0; i < 10; i++) for (int j = 0; j < i; j++) System.out.println(i * j)
31) A) 100 B) 10 C) 20 D) 45 6
32) Analyze the following code. public class Test { public static void main(String[ ] args) { System.out.println(m(2)); } public static int m(int num) { return num; } public static void m(int num) { System.out.println(num); } }
32) A) The program runs and prints 2 once. B) The program runs and prints 2 twice. C) The program has a compile error because the two methods m have the same signature. D) The program has a compile error because the second m method is defined, but not invoked in the main method.
33) Which of the following is the best for generating random integer 0 or 1?
33) A) (int)Math.random() B) (int)(Math.random() + 0.2) C) (int)(Math.random() + 0.8) D) (int)Math.random() + 1 E) (int)(Math.random() + 0.5) 3
34) Variables that are shared by every instances of a class are ________.
34) A) private variables B) class variables C) instance variables D) public variables
35) Which of the following operators are right-associative?
35) A) + B) % C) * D) = E) &&
Explanation / Answer
31)D.45
To each I th in external loop and the internal loop runs i times.
internal loop begins at 0 and terminates at 9.
0+1+2+3+4+5+6+7+8+9
=45
32)C.The programm has a compile error because the two methods m have the same signature.
33) (int) (Math.random()+0.5)
34)B.Class variables
35)D.= (equal operator)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.