Guest User

Untitled

a guest
Feb 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. package com.sandbox.test01;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.    
  7.  
  8.     public static void main(String args [])
  9.     {
  10.  
  11.         //First 1 dimension array
  12.         int a [] = new int [10]; //allocate memory (capacity is 10)
  13.         for(int i = 0; i < a.length; i++)
  14.         {
  15.             a[i] = i; //Initialize the array with values 0 - 9
  16.             System.out.println("A[" + i + "] : " + a[i]);
  17.         }
  18.        
  19.         //Second 1 dimension array
  20.         int b [] = new int [5]; //allocate memory (capacity is 5)
  21.         for(int i = 0; i < b.length; i++)
  22.         {
  23.             b[i] = (i * 10); //Initialize the array with values 0-40
  24.             System.out.println("B[" + i + "] : " + b[i]);
  25.         }
  26.        
  27.         //First 2 dimension array
  28.         int z [] [] = new int[10][]; //allocate memory for 10 arrays but no allocation for the arrays within
  29.        
  30.         //Assign array[0] to be equal to a
  31.         z[0] = a;
  32.         //Print length of Z
  33.         System.out.println(z[0].length);
  34.        
  35.         //Print contents of z[0]
  36.         for(int i=0; i < z[0].length; i++)
  37.         {
  38.             System.out.println("Z[" + i + "] : " + z[0][i]);
  39.         }
  40.        
  41.         //Assign array[0] to be equal to b
  42.         z[0] = b;
  43.         //Print length of Z
  44.         System.out.println(z[0].length);
  45.        
  46.         //Print contents of z[0]
  47.         for(int i=0; i < z[0].length; i++)
  48.         {
  49.             System.out.println("Z[" + i + "] : " + z[0][i]);
  50.         }
  51.        
  52.        
  53.         return;    
  54.     }
  55. }
Add Comment
Please, Sign In to add comment