Wednesday 13 February 2013

Java program to add two three dimensional (3D) array.

package arraythree1;
import java.util.Scanner;
public class ArrayThree1
{
    public static void main(String[] args)
    {
        int i,j,k;
        int[][][] threeD =new int [2][3][2];
  Scanner input = new Scanner (System.in);

  Scanner input2 =new Scanner(System.in);
  int threeD2 [][][]=new int [2][3][2];

  System.out.printf("\nEnter the three dimension array1\n");
  for(i=0; i<2; i++)
  {
      for(j=0; j<3; j++)
  {
        for (k=0; k<2; k++ )
    {
    threeD[i][j][k] = input.nextInt();
    }
  }
  }
  System.out.printf("Enter the three dimension array2\n");
    for(i=0; i<2; i++)
  {
      for(j=0; j<3; j++)
  {
        for (k=0; k<2; k++ )
    {
    threeD2[i][j][k] = input2.nextInt();
    }
  }
  }

  System.out.printf("Your Entered array is \n");
  for(i=0; i<2; i++)
  {
      for(j=0; j<3; j++)
  {
        for (k=0; k<2; k++ )
  {
    System.out.printf(" %d ",threeD[i][j][k]);
  }
    System.out.println();    
  }
    System.out.println();     
  }

  System.out.printf("The sum of 3D array is \n");
  for(i=0; i<2; i++)
  {
      for(j=0; j<3; j++)
  {
        for (k=0; k<2; k++ )
  {
    System.out.printf(" %d ", (threeD[i][j][k]* threeD2[i][j][k]) );
  }
    System.out.println();    
  }
    System.out.println();     
  }

 
  }
}

No comments:
Write comments

Featured post

List of Universities in Karnataka offering M.Sc Computer Science

The post-graduate programme in Computer Science (M.Sc Computer Science) contains two academic years duration and having a four semesters....

Popular Posts

Copyright @ 2011-2022