Consider the following loop:
int n=1;
double x=0;
double s;
do
{
s=1.0 /(n * n) ;
x=x+5 ;
n++;
}
while (s>0.01) ;
System. out. println(x) ;
Which loop below is an equivalent loop?
A) double x=0;
double s=1;
for (int k=1 ; s>0.01 ; k++ )
{
s=1.0 /(k * k) ;
x=x+s ;
}
System. out. println(x) ;
B) double x=0;
double s=1;
for (int k=1 ; k<100 ; k++ )
{
s=1.0 /(k * k) ;
x=x+5;
}
System. out.println(x) ;
C) double x=0;
double s=1;
int k=10;
while (s>0.01)
{
s=1.0 /(k * k) ;
x=x+s ;
k++;
}
System.out. println(x) ;
D) double x=0;
double s=10;
int k=1;
while (s>0.01)
{
s=1.0 /(k * k) ;
x=x+s;
k++;
}
System.out. println(x) ;
Correct Answer:
Verified
Q55: Which of the following for loops is
Q56: How many times does the following loop
Q57: What does the following code snippet print?
Q58: How many times does the following loop
Q59: Which of the following loops executes 8
Q61: Is the following code snippet legal?
Q62: Which of the following statements is correct
Q63: What does the following code snippet display?
Q64: Which of the loop(s) test the condition
Q65: What will be the output of the
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents