I'm trying to print the following sequence infinitely:
0 100
1 99
2 98
. .
. .
. .
97 3
98 2
99 1
100 0
99 1
98 2
97 3
. .
. .
. .
3 97
2 98
1 99
0 100
. .
. .
. .
However, when I run this, the pattern only prints once.
Here's my code:
public class PrintSequence {
public static void main(String args[]) {
int i=0;
while(true)
{
if(i<=100) {
System.out.println(i+ " " + (100-i));
i++;
}
}
}
}
The assignment only allows me to use a single loop and a single variable.