Posted By:
3 Mar, 2014 1:56 pm PST

Array in JAVA

How to create One Dimensional and two dimensional array in Java?

♦ An array is a named list of data items that all have the same type.Array      names represent computer memory addresses that is array names contain  references as like all Java objects.

 You can initialize value to one D array and two D array as:

 int[] array = { 10,20,30,40}

 Example:

 //To print OneDimensional and two dimensional array

 public class ArrayExample{

           public static void main(String args[]){

                               int[] arrayOne ={10,20,30};

                               int[][] arrayTwo={{11,12},{13,14}, {14,15} };

                               System.out.println("One Dimensional Array");

                               for (int i=0; i<3; i++){

                                              System.out.println(arrayOne[i]+"\n");

                               }

                               System.out.println("Two Dimensional Array");

                               for(int j=0; j<=2;j++){

                                     for(int k=0; k<=1; k++){

                                              System.out.println(arrayTwo[j][k]+" ");

                                     }

                                      System.out.println("\n");

                               }

               }

}

              

Output of the above program is:

One Dimensional Array

10

20

30

 

Two Dimensional Array

11

12

13

14

15

16          

Attachment:None View Live Demo



Please login to reply to this problem.



Related Problems on Fixoncloud