Thursday, 17 December 2020

Pattern 23 and 24

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

OUTPUT

1 2 3 4 5 
2 3 4 5 1 
3 4 5 1 2 
4 5 1 2 3 
5 1 2 3 4 
public class P24 
{
	public static void main(String[] args) 
	{
		for(int i=5; i>0; i--)
		{
			for(int j=i; j<6; j++)
			{
				System.out.print(j + " ");
			}
			for(int k=1; k<i; k++)
			{
				System.out.print(k + " ");
			}
			System.out.println();
		}
	}
}

OUTPUT

5 1 2 3 4 
4 5 1 2 3 
3 4 5 1 2 
2 3 4 5 1 
1 2 3 4 5 

No comments:

Post a Comment

If you have any doubts, please let me know

Pattern 31 & 32