What is the condition in "if" statement in the piece of code below to produce the following output
4 9 14 19 end
int count = 1;
while (count <= 5)
{
if (_____)
System.out.print(5*count - 1 + " ");
else
System.out.print("end");
count++;
}
count != 5 |
||
count = 5 |
||
count < 5 |
||
!(count == 5) |
||
count > 5 |
There are three conditions out of given options that give the output mentioned.They are :
1.count!=5
2.count<5
3.!(count==5)
When these condition are used in the if statement and at the fifth iteration of the loop when the value of count becomes 5,the conditions turns out to be false and hence else statement gets executed for the last iteration printing the string value "end".
For the first 4 iterations when these conditions turn out to be true,the if statement gets executed printing the value of the expression 5*count -1 which is 4 for count 1,9 for count 2, 14 for count 3 and 19 for count 4.
So that the final output will be 4 9 14 19 end
Get Answers For Free
Most questions answered within 1 hours.