Ask Question
21 May, 11:21

Write a method called shifiLeft that takes a 2D array (that could be jagged) as an input and returns the same array with the elements shifted to the left by one position. The first element of the first row goes to the end of the last row. For example: input { {1, 2, 3}, output: { {2, 3, 4}, {4}, {5}, {5, 6, 7, 8}, {6, 7, 8, 9}, {9, 10}1 {10, 1}1

+4
Answers (1)
  1. 21 May, 12:42
    0
    Check the explanation

    Explanation:

    public static void main (String[] args) {

    int[][] twoDimenArray = new int[2][];

    //first row has 3 columns

    twoDimenArray[0] = new int[3];

    //second row has 4 columns

    twoDimenArray[1] = new int[4];

    int counter = 0;

    //initializing array

    for (int row=0; row < twoDimenArray. length; row++) {

    for (int col=0; col < twoDimenArray[row]. length; col++) {

    twoDimenArray[row][col] = counter++;

    }

    }

    //printing array

    for (int row=0; row < twoDimenArray. length; row++) {

    System. out. println ();

    for (int col=0; col < twoDimenArray[row]. length; col++) {

    System. out. print (twoDimenArray[row][col] + " ");

    }

    }

    }

    }

    Output

    0 1 2

    3 4 5 6
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a method called shifiLeft that takes a 2D array (that could be jagged) as an input and returns the same array with the elements ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers