SCRIPT 2026 UPDATED QUESTIONS WITH
DETAILED ANSWERS GRADED A+
⩥ 84) What will be the result of running the following code fragment?
int year = 0;
double rate = 5;
double principal = 10000;
double interest = 0;
while (year < 10)
{
interest = (principal * year * rate) / 100;
System.out.println("Interest " + interest);
}
a) The code fragment will display the interest calculated for nine years.
b) The code fragment will continue to display the calculated interest
forever because the loop will never end.
c) The code fragment will not display the calculated interest and halt
abruptly.
d) The code fragment will not display any output because it will not
compile.
,Answer: B. Answer: Answer: b) The code fragment will continue to
display the calculated interest forever because the loop will never end.
⩥ 85) Which of the following code snippets displays the output exactly
10 times?
a)
int i = 0;
while (i < 10);
{
System.out.println("This is example 1.");
i++;
}
b)
int i = 0;
while (i < 10)
{
System.out.println("This is example 2.");
i++;
}
c)
int i = 0;
,while (i < 10)
{
System.out.println("This is example 3.");
}
d)
int i = 1;
while (i < 10)
{
System.out.println("This is example 4.");
i++;. Answer: Answer: b)
int i = 0;
while (i < 10)
{
System.out.println("This is example 2.");
i++;
}
⩥ 86) What is the output of the following code snippet?
int i = 1;
while (i != 9)
{
, System.out.print(i + " ");
i++;
if (i == 9)
{
System.out.println("End");
}
}
a) 1 End
b) 1 End (infinite loop)
c) 1 2 3 4 5 6 7 8 End
d) 1 2 3 4 5 6 7 8 End (infinite loop). Answer: Answer: c) 1 2 3 4 5 6 7 8
End
⩥ 87) What changes do you need to make in the following code snippet
to display "Let us learn Java" exactly 10 times?
int i = 0;
while (i <= 10)
{
System.out.println("Let us learn Java");
i++;
}