0

The homework question is here : https://i.stack.imgur.com/lFNYs.jpg

An ArrayIndexOutOfBoundsException occurs when i try to transpose the array, and the question states that only one object can be used.

int arr, int n and and int m are instance variables. The input for m,n and arr[][] has been taken earlier.

void transpose(Transarray A){
    arr=new int[n][m];
    for (int i = 0; i < m; i++)
      for (int j = 0; j < n; j++)              
         arr[j][i] = A.arr[i][j];
   }
Abdelillah Aissani
  • 3,058
  • 2
  • 10
  • 25
  • 3
    Please don't link to images. In fact, don't use images at all except when your question is about graphics. Please [edit] your question, and add the problem description *in text*. Also, include the part that creates and fills the array and `n` and `m` (a [mcve]), otherwise we don't know what the problem is. – RealSkeptic Jul 29 '19 at 15:39

1 Answers1

0

Try

void transpose(Transarray A){
arr=new int[n][m];
for (int i = 0; i < m; i++)
  for (int j = 0; j < n; j++)              
     arr[i][j] = A.arr[j][i];
}