Java Programming - Flow Control - Discussion
Discussion Forum : Flow Control - Finding the output (Q.No. 9)
9.
What will be the output of the program?
int x = l, y = 6;
while (y--)
{
x++;
}
System.out.println("x = " + x +" y = " + y);
Answer: Option
Explanation:
Compilation fails because the while loop demands a boolean argument for it's looping condition, but in the code, it's given an int argument.
while(true) { //insert code here }
Discussion:
9 comments Page 1 of 1.
Jain said:
6 years ago
While can also takes condition too but as you said it only takes true argument ?
Sarvepalli Madhu Babu said:
8 years ago
Anyone explain it with one example.
Ankita said:
8 years ago
Please explain this with the example.
Please help me with this.
Please help me with this.
MentalFrostbyte said:
10 years ago
I knew it was compilation error because the problem states that x equals the letter 'l', not the number '1'.
Aroosh said:
1 decade ago
In Java while takes only Boolean values so seen while (1) will not work.
Rahul jain said:
1 decade ago
while(1)
{
//infinite loop, having int argument then why not this?
}
{
//infinite loop, having int argument then why not this?
}
Laasya said:
1 decade ago
While loop and if condition must have Boolean type argument that is either true or false but here there is no Boolean value it is a decrement operator.
Praveen said:
1 decade ago
While loop must have boolean type argument such as comparison.
Laxman.1249@gmail.com said:
1 decade ago
I don't know this answer. Please explain the answer.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers