Loop program

package com.vaannila.student;

public class MyLoop{
      public static void main(String argv[]){
      MyLoop ml = new MyLoop();
      ml.amethod();
      }

       public void amethod(){
                for(int K=0;K<5l;K++){
                     System.out.println("Outer "+K);
                     for(int L=0;L<5;L++)
                     {System.out.println("Inner "+L);}
                   }
          }
}

I was trying above example from link
http://www.jchq.net/certkey/0202certkey.htm
got output like



Outer 0
Inner 0
Inner 1
Inner 2
Inner 3
Inner 4
Outer 1
Inner 0
Inner 1
Inner 2
Inner 3
Inner 4
Outer 2
Inner 0
Inner 1
Inner 2
Inner 3
Inner 4
Outer 3
Inner 0
Inner 1
Inner 2
Inner 3
Inner 4
Outer 4
Inner 0
Inner 1
Inner 2
Inner 3
Inner 4


I was trying to understand the output.Why outer loop did not execute until 50 times( ask<51). Please advise. Any links, ideas, resources,sample code highly appreciated. thanks in advance.
LVL 7
gudii9Asked:
Who is Participating?
 
for_yanConnect With a Mentor Commented:

change this line:
  for(int K=0;K<5l;K++){

to this line:

  for(int K=0;K<51;K++){

It thinks that 5l is (long)5  and therefore compiler does not catch it

0
 
for_yanCommented:
That is not digit "1" but letter "l" which yu hvae in "51"  
0
 
for_yanCommented:
By the way if you want it to execute 50 times you should have it

K<50 (not K<51) as it starts with 0

 
0
 
gudii9Author Commented:
>>>That is not digit "1" but letter "l"

what is use of that character in this for loop. please advise
0
 
rrzConnect With a Mentor Commented:
>what is use of that character in this for loop.  
The  l   tells the compiler to make that number a long primitive type. But it is not really useful to do so. It makes no difference in this case.   It make be a typing mistake here.
http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.