Ask a Teacher



Write a program in Java to display the following pattern: 1 2 1 3 2 1 4 3 2 1 5 4 3 2 1

public static void displayPattern(int n)  
        {  
              
            for (int i = 1; i <= n; i++)   
            {     
            for (int k = 1; k <= n - 1; k++)  
                System.out.print("");  
              
            for (int j = 1; j <= i; j++)  
                  
                System.out.print(j + " ");  
                  
                          
            System.out.println();  
            }  
        } 


comments powered by Disqus