(TEST CORRECTIONS JAVA PROGRAMMING: WHY IS THIS THE CORRECT ANSWER AND WHAT IS THE CORRECT ANSWER FOR C-E) a) Which of the following correctly gives
(TEST CORRECTIONS JAVA PROGRAMMING: WHY IS THIS THE CORRECT ANSWER AND WHAT IS THE CORRECT ANSWER FOR C-E)
a) Which of the following correctly gives random numbers between -10 and 10 inclusively? Note: Math.random() creates a random number of [0,1).
Selected Answer:
int n = (int)(Math.random() * 10)-20;
Correct Answer:
int n = (int)(Math.random() * 21)-10;
---------------------------------------------
b) How many times is the println statement executed? for (int i = 0; i < 7; i++) for (int j = 0; j < i; j++) System.out.println(i * j);
Selected Answer: 7
Corrected Answer: 21
--------------------------------------------------------------------------
c) What is output? Convert the following loop into a for loop.
int sum = 10;
int i = 2;
while (i <= 6){
sum += 2 * i;
i++;
}
System.out.println(sum);
Your answer format: (no more than 6 lines)
Ouput: ________________
______________________ // Converted code
______________________
______________________
______________________
_______________________
Selected Answer:
for ( int i = 2; i < 7; i++)
for (int sum = 10; sum< i; sum += 2*i)
}
System.out.println(sum);
-----------------------------------------
d)
Write output produced by the following code. for (int i = 1; i <= 5; i++) { for (int j = 6; j >= i; j--) System.out.print(" * "); System.out.println(" ! "); } | |||||||||
Selected Answer:
|
Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started