1) Which of the following statements a. int c = 20 + (int) (Math.random () * 100); generates a random integer between b. int c = 20 + (Math.random () * 100); 20 and 100 both inclusive? c. int c = 20 + (Math.random () * 81); d.int c = 20 + (int) (Math.random () * 81); 2) How may a for-loop end up in an infinite loop? a. Forget the loop counter update b. No loop condition c. Loop condition is never reached d. All of the above 3) An else or else-if statement in Java cannot exist alone without an if а. True b. False statement. 4) How many times this for-loop will repeat? a. 20 times b. zero times c. infinite number of times d. 1 time int i=20 While (i>0) System.out.println ("CSCI250"); i++ ; = 0; i <= 10; i++) System.out.println (i); for (int i 5) Which of the for-loop statements is equivalent to the below do-while loop? int i = 0; a. b. for (int i = 0; i < 10; ) do { System.out.println (i); i++ ; System.out.println (i++); ) while (i < 10); С. for (int i = 0; i > 10; i++) System.out.println (i); d. for (int i = 1; i <= 10; i++) System.out.println (i); 6) Update the below code to output the even values of i, but three numbers per line. int i = 0; while (i <=120); { System.out.println (i); i++;

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 15SA
icon
Related questions
Question
Hello! These are multiple choice questions about Java programming
Answer
1) Which of the following statements
a. int c
= 20 +
(int)
(Math.random () *
100);
generates a random integer between
b. int c
20 + (Math.random()* 100);
20 and 100 both inclusive?
c. int c =
20 +
(Math.random () * 81);
d.int c = 20 + (int) (Math.random () * 81);
2) How may a for-loop end up in an
infinite loop?
a. Forget the loop counter update
b. No loop condition
c. Loop condition is never reached
d. All of the above
3) An else or else-if statement in Java
cannot exist alone without an if
a.
True
b.
False
statement.
4) How many times this for-loop will
repeat?
a. 20 times
b. zero times
c. infinite number of times
d. 1 time
int i=20
While (i>0)
System.out.println ("CSCI250");
i++ ;
for (int i = 0; i <= 10; i++)
System.out.println(i);
5) Which of the for-loop statements is
equivalent to the below do-while loop?
int i = 0;
do {
System.out.println (i);
i++ ;
a.
b.
for (int i = 0; i < 10; )
System.out.println (i++);
for (int i = 0; i > 10; i++)
System.out.println (i);
C.
} while (i < 10);
d.
for (int i = 1; i <= 10; i++)
System.out.println (i);
6) Update the below code to output the
even values of i, but three numbers
per line.
int i = 0;
while (i <=120); {
System.out.println (i);
i++;
Transcribed Image Text:Answer 1) Which of the following statements a. int c = 20 + (int) (Math.random () * 100); generates a random integer between b. int c 20 + (Math.random()* 100); 20 and 100 both inclusive? c. int c = 20 + (Math.random () * 81); d.int c = 20 + (int) (Math.random () * 81); 2) How may a for-loop end up in an infinite loop? a. Forget the loop counter update b. No loop condition c. Loop condition is never reached d. All of the above 3) An else or else-if statement in Java cannot exist alone without an if a. True b. False statement. 4) How many times this for-loop will repeat? a. 20 times b. zero times c. infinite number of times d. 1 time int i=20 While (i>0) System.out.println ("CSCI250"); i++ ; for (int i = 0; i <= 10; i++) System.out.println(i); 5) Which of the for-loop statements is equivalent to the below do-while loop? int i = 0; do { System.out.println (i); i++ ; a. b. for (int i = 0; i < 10; ) System.out.println (i++); for (int i = 0; i > 10; i++) System.out.println (i); C. } while (i < 10); d. for (int i = 1; i <= 10; i++) System.out.println (i); 6) Update the below code to output the even values of i, but three numbers per line. int i = 0; while (i <=120); { System.out.println (i); i++;
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Constants and Variables
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++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning