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]);
}
}
}
The following programaverage stores integer numbers in onlarray coled table and compute the average of innermost...
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 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 /...
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]); }}
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...
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 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, 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]...
. In the method main, prompt the user for a non-negative integer and store it in an int variable num (Data validation is not required for the lab). Create an int array whose size equals num+10. Initialize the array with random integers between 0 and 50 (including 0 and excluding 50). Hint: See Topic 4 Decision Structures and File IO slides page 42 for how to generate a random integer between 0 (inclusive) and bound (exclusive) by using bound in...
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...
How to measure the average performance of sorting algorithms with different sizes and numbers(with arrayList<Integer>) and compare with a graph? I have these methods: //This one receives one size(n) parameter public static ArrayList<Integer> RandomArray(int n){ ArrayList<Integer> randomArray = new ArrayList<Integer>(n); Random rand = new Random(); //--- random number rand.setSeed(System.currentTimeMillis()); for(int i = 0; i < n; i++ ) { //loop for creating...