shivamisone

samplepaper2ques7

Aug 22nd, 2023
765
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | Source Code | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.  * sampletwoquestion_seven
  5.  */
  6. public class shift {
  7.     static int m, n;
  8.     static int[][] mat;
  9.     static int[][] mat2;
  10.  
  11.     shift() {
  12.         int mm = m;
  13.         int nn = n;
  14.     }
  15.  
  16.     public static void main(String[] args) {
  17.         shift ob = new shift();
  18.         ob.input();
  19.         ob.cyclic();
  20.         ob.display();
  21.     }
  22.  
  23.     void input() {
  24.         Scanner sc = new Scanner(System.in);
  25.         System.out.println("enter row size of array:");
  26.         m = sc.nextInt();
  27.         System.out.println("enter column size of array:");
  28.         n = sc.nextInt();
  29.         mat = new int[m][n];
  30.         mat2 = new int[m][n];
  31.         for (int i = 0; i < m; i++) {
  32.             for (int j = 0; j < n; j++) {
  33.                 mat[i][j] = sc.nextInt();
  34.             }
  35.         }
  36.     }
  37.  
  38.     void cyclic() {
  39.         for (int i = 0; i < m; i++) {
  40.             for (int j = 0; j < n; j++) {
  41.                 if (i + 1 == m) {
  42.                     mat2[0][j] = mat[i][j];
  43.                 } else
  44.                     mat2[i + 1][j] = mat[i][j];
  45.             }
  46.         }
  47.     }
  48.  
  49.     void display() {
  50.         for (int i = 0; i < m; i++) {
  51.             for (int j = 0; j < n; j++) {
  52.                 System.out.print(mat2[i][j] + ",");
  53.             }
  54.             System.out.println("");
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment