Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- * sampletwoquestion_seven
- */
- public class shift {
- static int m, n;
- static int[][] mat;
- static int[][] mat2;
- shift() {
- int mm = m;
- int nn = n;
- }
- public static void main(String[] args) {
- shift ob = new shift();
- ob.input();
- ob.cyclic();
- ob.display();
- }
- void input() {
- Scanner sc = new Scanner(System.in);
- System.out.println("enter row size of array:");
- m = sc.nextInt();
- System.out.println("enter column size of array:");
- n = sc.nextInt();
- mat = new int[m][n];
- mat2 = new int[m][n];
- for (int i = 0; i < m; i++) {
- for (int j = 0; j < n; j++) {
- mat[i][j] = sc.nextInt();
- }
- }
- }
- void cyclic() {
- for (int i = 0; i < m; i++) {
- for (int j = 0; j < n; j++) {
- if (i + 1 == m) {
- mat2[0][j] = mat[i][j];
- } else
- mat2[i + 1][j] = mat[i][j];
- }
- }
- }
- void display() {
- for (int i = 0; i < m; i++) {
- for (int j = 0; j < n; j++) {
- System.out.print(mat2[i][j] + ",");
- }
- System.out.println("");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment