Multiple Choice
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
Correct Answer:
Verified
Q42: The command line interface of your operating
Q43: What for loop can be used in
Q44: What is the output of the following
Q45: How many times will the following loop
Q46: Is the following code snippet legal? <img
Q48: Which of the following should be used
Q49: What is the output of the following
Q50: How many times does the code snippet
Q51: Given the following code snippet, what should
Q52: How many times does the loop execute