Monday, September 21, 2015

Two dimensional array in java


 

public class Apples {



public static void main(String[] args){

int [][] array1 = {{1,2,3},{4,5,6}};

int [][] array2 = {{1,2},{3},{4,5,6}};

System.out.println("elements of array1 by row");

outputArray(array1);

System.out.println(" \n elements of array2 by row");

outputArray(array2);



}

public static void outputArray(int[][] array){

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

for(int column=0; column < array[row].length ; column++){

System.out.printf(" %d " , array[row][column]);



}

System.out.println();


}

}

}

1 comment:

  1. Nice class ,xD Learning more each class , thank you Mr.Gabr

    ReplyDelete