+ 1
Can any 1 explain me how this is..? Give the ans too.
int i=3; for(i=5; i<i*i; i--) { System.out.println(I);}
8 Respuestas
+ 9
From where did you get this code?
The first assignement is unnecessary, because on second line you reassign a new value ( 5 instead 3 ) to 'i'...
And the loop defined on second line is a complex declaration loop also unnecessary, because it's equivalent to: 'for (i=5; i!=1; i--)', as testing 'i<i*i' is always true while i is different of one ^^
Anyway, the loop print an undeclared/unassigned variable 'l' five times ( first i==5, second 4... finally 2, stopped when i==1 ).
+ 5
@Visph it's a Java challenge quizz, hence the unnecessary assignment 😉
+ 4
@Rrestoring faith: You're right... I've written too quick @@ ( previous post edited ;) )
+ 4
@Siddahart Upadhyay answer isn't right, as there is 2 variables in the example, 'i' and 'l', not only one "l" ^^
+ 1
Thank you all ...! now i got it .
+ 1
then the program should show an error due to uninitialized variable I
so no output for this question
0
@Visph the loop stops when i is 1, not 0.
0
Output for this code will be
5432
because I=5 checks the condition and it's satisfies and print it and the process continues till 1 and stop because it happen like this
5<25 True
4<16 true
3<9 true
2<4true
1<1 false