Here's an example of using a for loop in JAVA. This program uses a loop inside another to create a list of integers where the number on the left goes between 1 to 4, and the other goes between 2 to 4, making sure the second number is printed as higher than the first number and going through the cut cycle.
public class LoopingProblemNumber1
{
public static void main(String[] args)
{
for (int x = 1; x <= 3; x++)
{
for (int y = x + 1; y <= 4; y++)
{
System.out.println(x + "\t" + y);
}
}
}
}
Output:
1 2
1 3
1 4
2 3
2 4
3 4
public class LoopingProblemNumber1
{
public static void main(String[] args)
{
for (int x = 1; x <= 3; x++)
{
for (int y = x + 1; y <= 4; y++)
{
System.out.println(x + "\t" + y);
}
}
}
}
Output:
1 2
1 3
1 4
2 3
2 4
3 4