Slip 5 - A) Write a java program to display following pattern: 5 4 5 3 4 5 2 3 4 5 1 2 3 4 5

Solution: 

public class Slip5
{
    public static void main( String[] args) {
        int n=6;
        for (int i = 1; i<n; i++) {
            for (int j = n-i; j<n; j++) {
                System.out.print(j+" ");
            }
            System.out.println();
        }
    }
}

Output:

Output_pic


Post a Comment

0 Comments