Question

In: Computer Science

Create a program using Java. Create two different 3D arrays with random numbers. (lets name them...

Create a program using Java.

Create two different 3D arrays with random numbers. (lets name them array1 and array 2)

Add the two 3Darrays together and then get the average.

Save the average on a separate 3D array.(lets name it array3)

Then add array1 and array3 then get the average

Save the average on a separate 3Darray(lets name it array 4)

Then add array2 and array3 then get the average

Save the average on a separate 3Darray (lets name it array5)

Use recursion

Solutions

Expert Solution

CODE

import java.util.Arrays;

import java.util.Random;

public class Main

{

public static double[][][] getRandomArray(int a, int b, int c) {

double[][][] arr = new double[a][b][c];

Random random = new Random();

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

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

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

arr[i][j][k] = random.nextInt(100);

}

}

}

return arr;

}

public static double[][][] average(double array1[][][], double array2[][][], int a, int b, int c) {

double[][][] arr = new double[a][b][c];

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

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

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

arr[i][j][k] = (array1[i][j][k] + array2[i][j][k])/2;

}

}

}

return arr;

}

public static void printArray(double arr[][][]) {

for (int i=0; i<arr.length; i ++) {

for (int j=0; j<arr[i].length; j++) {

for (int k=0; k<arr[i][j].length; k++) {

System.out.print(arr[i][j][k] + " ");

}

System.out.println();

}

}

}

public static void main (String[] args)

{

double array1[][][] = getRandomArray(3, 3, 3);

double array2[][][] = getRandomArray(3, 3, 3);

double array3[][][] = average(array1, array2, 3, 3, 3);

double array4[][][] = average(array1, array3, 3, 3, 3);

double array5[][][] = average(array2, array3, 3, 3, 3);

printArray(array1);

System.out.println();

printArray(array2);

System.out.println();

printArray(array3);

System.out.println();

printArray(array4);

System.out.println();

printArray(array5);

}

}


Related Solutions

how to create BANKACCOUNT program using Arrays in JAVA.
how to create BANKACCOUNT program using Arrays in JAVA.
Create a program that generates a file of random numbers, and then prints them in neat...
Create a program that generates a file of random numbers, and then prints them in neat fashion to another file, and also saves to that file the average and standard deviation of those numbers. I) First, you would need to generate a file of random numbers that consists of N random numbers (100 < N < 1000). Each random digit should be a real number (type double) between 0 and 50. This file and its digits would now serve as...
Java program problem 1 Come up with an idea for parallel arrays Create the arrays to...
Java program problem 1 Come up with an idea for parallel arrays Create the arrays to hold 5 items in each In the main(), load the arrays with data Then output the entire contents of the arrays Create a method called find1() and pass the 2 arrays to that method. problem 2 In the find1() method, ask the user to enter a value to search for Write logic to search the first array and then output the related data from...
Create a C++ file with given instructions below- Analyze random numbers Create two arrays, one int...
Create a C++ file with given instructions below- Analyze random numbers Create two arrays, one int one double. They should have 10 elements each Ask the user how many random numbers to generate. Then generate that many random numbers between 1 and 10. Use a for loop. Keep track of how many of each number in the range was generated (1 to 10) in the int array. Be sure to initialize the array to all 0's to start. Then, send...
****java*** Create an application that generates 20 random numbers between 1 and 100 and writes them...
****java*** Create an application that generates 20 random numbers between 1 and 100 and writes them to a text file on separate lines. Then the program should read the numbers from the file, calculate the average of the numbers, and display this to the screen.
java program Create a program that creates and prints a random phone number using the following...
java program Create a program that creates and prints a random phone number using the following format: XXX-XXX-XXXX. Make sure your output include the dashes.  Do not let the first three digits contain an 8 or 9 (HINT: do not be more restrictive than that) and make sure that the second set of three digits is not greater than 773. Helpful Hint:   Think though the easiest way to construct the phone number. Each digit does do not have to be determined...
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2....
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2. Pass arrays to method and return an array from a method Problem 2: Find the largest value of each row of a 2D array             (filename: FindLargestValues.java) Write a method with the following header to return an array of integer values which are the largest values from each row of a 2D array of integer values public static int[] largestValues(int[][] num) For example, if...
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2....
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2. Pass arrays to method and return an array from a method Problem 1: Find the average of an array of numbers (filename: FindAverage.java) Write two overloaded methods with the following headers to find the average of an array of integer values and an array of double values: public static double average(int[] num) public static double average(double[] num) In the main method, first create an...
java programming write a program with arrays to ask the first name, last name, middle initial,...
java programming write a program with arrays to ask the first name, last name, middle initial, IDnumber and 3 test scores of 10 students. calculate the average of the 3 test scores. show the highest class average and the lowest class average. also show the average of the whole class. please use basic codes and arrays with loops the out put should look like this: sample output first name middle initial last name    ID    test score1 test score2...
Using import java.util.Random, create a simple java code that populates an array with 10 random numbers...
Using import java.util.Random, create a simple java code that populates an array with 10 random numbers and then outputs the largest number.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT