1 2 3 6 5 4 7 8 9 12 11 10 13 14 15
public class NumberPattern8
{
    public static void main(String[] args)
    {
        int n = 5; // Number of rows
        int num = 1; // Starting number
        for(int i=1; i<=n; i++)
        {
            if (i % 2 != 0)     // For odd rows, print numbers in increasing order
            {
                for(int j=1; j<=3; j++)
                {
                    System.out.print(num + "  ");
                    num++;
                }
            }
            else    // For even rows, print numbers in decreasing order
            {
                int temp = num + 2; // Store the highest value in the row
                for(int j=1; j<=3; j++)
                {
                    System.out.print(temp + "  ");
                    temp--;
                    num++;
                }
            }
            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.