Virajsinh

Java_10

Feb 11th, 2018
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. //Write a java program to explain of array.
  2. //Single Dimensional Array and Multidimensional Array
  3.  
  4. class Ex10 // Ex10 is FileName
  5. {
  6.     public static void main(String args[])
  7.     {
  8.         //First Type Declaration in Single dimensional Array
  9.         int a[] = new int[5];
  10.         a[0]=10;
  11.         a[1]=20;
  12.         a[2]=30;
  13.         a[3]=40;
  14.         a[4]=50;
  15.        
  16.         //Second Type Declaration in Single dimensional Array
  17.         int b[] = {1,2,3,4,5};
  18.        
  19.         //First Type Declaration in Multidimensional Array
  20.         int arr[][] = {{1,2,3},{4,5,6},{7,8,9}};
  21.        
  22.         //Second Type Declaration in Multidimensional Array
  23.         arr[0][0]=1;  
  24.         arr[0][1]=2;  
  25.         arr[0][2]=3;  
  26.         arr[1][0]=4;  
  27.         arr[1][1]=5;  
  28.         arr[1][2]=6;  
  29.         arr[2][0]=7;  
  30.         arr[2][1]=8;  
  31.         arr[2][2]=9;  
  32.        
  33.         //length is the property of array
  34.         for(int i=0;i<a.length;i++)  
  35.         {  
  36.             System.out.println(a[i]);
  37.         }
  38.        
  39.         for(int i=0;i<b.length;i++)  
  40.         {  
  41.             System.out.println(b[i]);
  42.         }
  43.        
  44.         for(int i=0;i<3;i++)
  45.         {  
  46.             for(int j=0;j<3;j++)
  47.             {  
  48.                 System.out.print(arr[i][j]+" ");  
  49.             }  
  50.             System.out.println();
  51.         }  
  52.     }
  53. }
Add Comment
Please, Sign In to add comment