1 2 6 3 7 10 4 8 11 13 5 9 12 14 15
public class NumberPattern7
{
public static void main(String[] args)
{
for(int i=1; i<=5; i++)
{
int num = i; // Start number for each row
for(int j=1; j<=i; j++)
{
System.out.print(num+" ");
num = num + (5 - j); // Increase the number by (n - j)
}
System.out.println();
}
}
}
Your feedback helps us grow! If there's anything we can fix or improve, please let us know.
We’re here to make our tutorials better based on your thoughts and suggestions.