Printing 2D array using recurrence method

class Pattern2DArray{
import java.io.*;
class Matrix{
 static int i=0,j=0;
 public static void main(String ar[])throws IOException{
  int a[][]={{1,2,3},{2,2,2},{1,2,3}}; 
  printArray(a);
 }
 public static void printArray(int arr[][]){
  if(i>arr.length-1)
  {
   return;
  }
  else
  {
   System.out.print(" "+arr[i][j]);
   
   if(i<arr.length && j==arr[i].length-1){
    i++;
    j=0;
    System.out.println();
    printArray(arr);
   }else{
    j++;
    printArray(arr);
   }
  }
 }
}

No comments:

Popular Posts