Question

The following programaverage stores integer numbers in onlarray coled table and compute the average of innermost array The av

0 0
Add a comment Improve this question Transcribed image text
Answer #1
class averageMultiDim{
    public static void main(String args[]){

        int[][][] table = {{{1,2,3},{0,57,101}},{{38,-80,95},{-10,14,34}}};

        double[] sumArr = new double[4];
        int sum = 0;
        int index = 0;

        System.out.println("Sizes"+table.length+table[0].length+table[0][0].length);

        for(int i = 0;i<table.length;++i)
        {
            for(int j = 0;j<table[0].length;++j)
            {
                sum = 0;
                for(int k = 0;k<table[0][0].length;++k)
                {
                    //storing sum of each 1D array
                    sum = sum + table[i][j][k];
                }
                //calculating average of calculated sum
                double average = (1.0)*sum/table[0][0].length;//multiplied by 1.0 to get decimal result
                //storing array in the sumArr
                sumArr[index++] = average;
            }
        }

        //FOR TESTING
        //dsiplaying sumArr for testing
        for(int i=0;i<sumArr.length;++i){
            System.out.println(sumArr[i]);
        }
    }
}

[Pratyushs-MacBook-Pro:java pthapli$ javac averageMultiDim.java [Pratyushs-MacBook-Pro:java pthapli$ java averageMultidim Siz

1 class averageMultiDim{ Run Debug public static void main(String args[]) { 2 3 4 5 int[] [] [] table = {{{1,2,3},{0,57, 101}

Add a comment
Know the answer?
Add Answer to:
The following programaverage stores integer numbers in onlarray coled table and compute the average of innermost...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Could someone please solve it? its java - The average of each integer array is stored...

    Could someone please solve it? its java - The average of each integer array is stored in another array coedum Answer the three questions below using this program public class averageMultidin 2 public static void main(String[] args) { int(01) tablet (1,2,3), (0,57,101) },{ (38,-80,95),(-10,13,34) ) ); 5 3 double[] sumar - new double 4); int sum = 0; int index = 0; 9 11 System.out.println("Sizesi "table.length-table().length. table[ejto).length); 12 for (int i = 0; i < table.length; i++) for (int j...

  • In the code shown above are two parts of two different exercises. HOW WE CAN HAVE...

    In the code shown above are two parts of two different exercises. HOW WE CAN HAVE BOTH OF THEM ON THE SAME CLASS BUT SO WE CAN RECALL them threw different methods. Thank you. 1-First exercise import java.util.Scanner; public class first { public static int average(int[] array){    int total = 0;    for(int x: array)        total += x;    return total / array.length;    } public static double average(double[] array){    double total = 0;    for(double x: array)        total += x;    return total /...

  • Write a program that stores a phrase as an array of words, and then prints it...

    Write a program that stores a phrase as an array of words, and then prints it backwards. The main method calls method getInput , which asks the user how many words there are, stores them in an array, and returns this array. printBackwards then takes this array of words, and prints it in reverse. Code Example: import java.util.Scanner; public class L17Num1{    public static void main(String[] args) {    String[] sArray=getInput(); printBackwards(sArray); } public static String[] getInput() { System.out.println("How many...

  • Correct any errors and change the integer numbers. what would the output be? public static void...

    Correct any errors and change the integer numbers. what would the output be? public static void main(String args[]){ int a[]={33,3,4,5};//declaration, instantiation and initialization //printing array System.out.println(a[i]); }}

  • need help editing or rewriting java code, I have this program running that creates random numbers...

    need help editing or rewriting java code, I have this program running that creates random numbers and finds min, max, median ect. from a group of numbers,array. I need to use a data class and a constructor to run the code instead of how I have it written right now. this is an example of what i'm being asked for. This is my code: import java.util.Random; import java.util.Scanner; public class RandomArray { // method to find the minimum number in...

  • JAVA HELP: Directions Write a program that will create an array of random numbers and output...

    JAVA HELP: Directions Write a program that will create an array of random numbers and output the values. Then output the values in the array backwards. Here is my code, I am having a problem with the second method. import java.util.Scanner; import java.util.Random; public class ArrayBackwards { public static void main(String[] args) { genrate(); print(); } public static void generate() { Scanner scanner = new Scanner(System.in);    System.out.println("Seed:"); int seed = scanner.nextInt();    System.out.println("Length"); int length = scanner.nextInt(); Random random...

  • I spotted a couple of errors, but I am still not getting this code to work....

    I spotted a couple of errors, but I am still not getting this code to work. Can someone help? public class Bounds1{ int [][] a1; public Bounds1(){ /* * Create array Dimension 1 */ a1 = new int[(int)(Math.random() * 10) + 1][]; for(int i = 0; i < a1.length; ++i){ /* * Create array Dimensions 2 */ a1[i] = new int[(int)(Math.random() * 20) + 1]; } } public static void main(String[] args){ Bounds1 m = new Bounds1(); for(int i =...

  • In the following program, declare an integer array daysInMonth that stores the number of days in January, February, March, April, and so on

    # JAVA In the following program, declare an integer array daysInMonth that stores the number of days in January, February, March, April, and so on. Fill it with the appropriate values (31, 28, 31, 30, ...).The program reads a month and year from the user.When the year is a leap year, change the entry for February to 29.Print out how many days the given month has.CODE:import java.util.Scanner;public class NumberOfDays{   public static void main(String[] args)   {      // Declare and initialize daysOfMonth      ....

  • I'm writing this class called CharArrayProject_3 that removes repeating elements from an array of chars. However,...

    I'm writing this class called CharArrayProject_3 that removes repeating elements from an array of chars. However, when I run the driver class, it just outputs two sets of dashed lines. What am I getting wrong? Is it the deleteRepeats() method?: public class CharArrayProject_3 { private char[] array; privateint length; privateintnumberOfRepeats; public CharArrayProject_3( char[] arr ) { length = arr.length; array = new char[ length ]; numberOfRepeats = 0; for( int k = 0; k < arr.length; k++ ) { array[k]...

  • The following code is a Java code for insertion sort. I would like this code to...

    The following code is a Java code for insertion sort. I would like this code to be modified by not allowing more than 10 numbers of integer elements (if the user enters 11 or a higher number, an error should appear) and also finding the range of the elements after sorting. /* * Java Program to Implement Insertion Sort */ import java.util.Scanner; /* Class InsertionSort */ public class InsertionSortTwo { /* Insertion Sort function */ public static void sort( int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT