I need nested while loops to print so that the outter loop k makes one decrement iteration every time that inner loop "I" finishes an iteration. K has to start at 5 and count back to 1 and I has to starts at 0 and count to 10 by 2's. So it would the out put would look like this:
K = 5 I = 0
K = 5 I = 2
K = 5 I = 4
K = 5 I = 6
K = 5 I = 8
K = 5 I = 10
K = 4 I = 0
I have been stumped for hours and tried everyway to I can think of to make it work. Can someone please help?
public class Task1 {
public static int i = 0;
public static int k = 5;
public static void Display(){
while(k > 1){
while(i >=10){
i = i+2;
System.out.println("K = " + k + " I = " + i);
}
if (i >= 10){
k=k-1;
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Display();
}
}
for( int i = 5; i > 0; i-- ) for( int j = 0; j <= 10; j = j+2 ) System.our.println( i + " " + j);of course making same with whole loops is trivial if you have seen that aforloop is very much like a while loop.