Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Write a java program to explain of array.
- //Single Dimensional Array and Multidimensional Array
- class Ex10 // Ex10 is FileName
- {
- public static void main(String args[])
- {
- //First Type Declaration in Single dimensional Array
- int a[] = new int[5];
- a[0]=10;
- a[1]=20;
- a[2]=30;
- a[3]=40;
- a[4]=50;
- //Second Type Declaration in Single dimensional Array
- int b[] = {1,2,3,4,5};
- //First Type Declaration in Multidimensional Array
- int arr[][] = {{1,2,3},{4,5,6},{7,8,9}};
- //Second Type Declaration in Multidimensional Array
- arr[0][0]=1;
- arr[0][1]=2;
- arr[0][2]=3;
- arr[1][0]=4;
- arr[1][1]=5;
- arr[1][2]=6;
- arr[2][0]=7;
- arr[2][1]=8;
- arr[2][2]=9;
- //length is the property of array
- for(int i=0;i<a.length;i++)
- {
- System.out.println(a[i]);
- }
- for(int i=0;i<b.length;i++)
- {
- System.out.println(b[i]);
- }
- for(int i=0;i<3;i++)
- {
- for(int j=0;j<3;j++)
- {
- System.out.print(arr[i][j]+" ");
- }
- System.out.println();
- }
- }
- }
Add Comment
Please, Sign In to add comment