gudii9
asked on
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.
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
}
}
}
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.
That is not digit "1" but letter "l" which yu hvae in "51"
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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
K<50 (not K<51) as it starts with 0
ASKER
>>>That is not digit "1" but letter "l"
what is use of that character in this for loop. please advise
what is use of that character in this for loop. please advise
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.