0
See my qes.
class HelloWorld { public static void main(String[] args) { String s="abcdef"; char c[]=s.toCharArray(); for(int i=c.length-1;i==0;i--){ System.out.println(c[i]);} } } class HelloWorld { public static void main(String[] args) { String s="abcdef"; char c[]=s.toCharArray(); for(int i=c.length-1;i==0;i--){ System.out.println(c[i]);} } } Why "for(int i=c.length-1;i==0;i--)" for loop is not working here with i==0 And working with "for(int i=c.length-1;i>=0;i--)" Why?
3 Answers
+ 3
Knowing that
<i> is length of string - 1
Condition
<i> == 0 is not true. When condition evaluates to false even from the beginning, the loop doess not even get started.
+ 1
Thnxx Ipang
+ 1
No problem đ