Computer Science, asked by ajithqtr15, 5 months ago


Write a program using Java to print the following pattern. The number of rows should be obtained from the user into an integer variable
Sample input:
5
Sample 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​

Answers

Answered by BrainlyProgrammer
1

Answer:

Question:-

  • To print in Java the following pattern taking no. of rows as input.

Sample Input:

5

Sample Output:

12345

23451

34512

45123

51234

Code:-

import java.util.*;

class Code

{

public static void main (String ar [])

{

Scanner sc=new Scanner (System.in);

/*

*Solved By:-

*@swetank232894

*/

System.out.println("Enter no. of rows");

int n=sc.nextInt();

System.out.println("Pattern is as follows...");

for(I=1;I<=n;I++)

{

for(j=I;j<=n;j++)

{

System.out.print(j+" ");

}

for(j=1;j<I;j++)

{

System.out.print(j);

}

System.out.println();

}

}

}

Variable Description:-

n--------Input variable to accept no. of rows from user

I---------Loop variable

j---------Loop variable

Output seen in terminal window:-

Enter no. of rows:

5

Pattern is as follows...

12345

23451

34512

45123

51234

Similar questions