In Java? OKay. the answers are:-
1) 123456789
2) 2345678910
3) 9876543210-1-2-3-4-5-6-7-8-9.........
EXPLANATIONS:-
CASE I)
A Do...While loop always executes its body atleast once irrespective of the condition. Here we are initializing x as 1. The first time it will enter the loop and print 1. Then it check the condition (1 <10) which is true. so the loop executes again till y = 10 coz (10 < 10) is not true. (How can 10 be lesser then 10 man?). So the output will be 123456789
CASE II)
Its a slightly different case. Here we are initializing z as 1. The the control enter the loop where 'z' is first incremented. So z will be 2. When comes to print naturally it will print 2. Then it checks the condition (2 < 10) which is true. There fore it executes its body again till the value of z = 10. (NOTE:- It prints 10 because after checking the condition 9 > 10 the loop executes again and the value of z is incremented to 10. Therefore 10 is printed). Then it check the condition 10 > 10 which is false and therefore the control is thrown out of the loop and the program continues.
3. CASE III)
According to my knowledge, this program is never ending. Lets trace it. First we initialize the value of y to 10. Then the control enters the loop where y is decremented to 9. Therefore it prints 9. Then it checks the condition (9 < 10) which is true. Therefore the loop executes again forever. Coz after 0 the value will be decremented to -1 which is lesser than 10. Keep waiting until the program ends.
And if it does be sure to inform me...
Senthil
2006-08-10 02:25:44
·
answer #1
·
answered by Senthil 3
·
1⤊
2⤋
Case 1.
Result = 1,2,3,4,5,6,7,8,9
Case 2.
Result = 2,3,4,5,6,7,8,9
Case 3. (If you really mean declare y instead of i)
Result = error
Case 3. (If you commited an error and you mean z intead of i)
Result = 9,8,7,6,5,4,3,2,1,0,-1,-2,-3 ... -32,767 (16 bits)
Result = 9,8,7,6,5,4,3,2,1,0,-1,-2,-3 ... -â2,147,483,648 (32 bits)
2006-08-14 13:09:19
·
answer #3
·
answered by dyohanan 3
·
0⤊
0⤋
Output for (i) is:
1
2
3
4
5
6
7
8
9
Output for (ii) is:
2
3
4
5
6
7
8
9
10
(iii)In this case we find an compile time error bcoz the variable i is not declared or if declared it is not initialized
2006-08-10 10:20:34
·
answer #4
·
answered by sree 2
·
1⤊
1⤋
i) outputs 1 through 9
ii) outputs 2 through 10
iii) indeterminate, the variable i is undefined, so will give a compile error
2006-08-10 09:08:47
·
answer #5
·
answered by justme 7
·
2⤊
1⤋
i) 1
ii) 2
iii) nothing because i is not initialised
The reason for this is the do loop closes before the while loop.
So your while loop is doing nothing.
2006-08-10 09:04:13
·
answer #7
·
answered by leighgriffin_ie 3
·
1⤊
1⤋