Answer the question
In order to leave comments, you need to log in
How to pass the rendered array?
Good afternoon!
I need help, I can’t either drive the output array into the method, or correctly call the method with the correct parameters.
import java.util.Scanner;
import static java.lang.Math.*;
public class OneDimensionalArray {
//создание и заполнение массива
static double createRandomArray(int size) {
double[][] da = new double[size][size];
for(int i=0; i<da.length; i++) {
for(int j=0; j<da[i].length; j++) {
da[i][j] = (Math.random()*100);
}
}
for(int i=0; i<da.length; i++) {
for(int j=0; j<da[i].length; j++) {
System.out.print(da[i][j] + "\t");
}
System.out.println();
}
return 0;
}
//задание найти среднее арифметическое - сумма всех чисел деленная на их количество
static double mean(double[][] array) {
double total=0;
int totallength = 0;
for(int i=0;i<array.length;i++) {
for(int j=0;j<array[i].length;j++) {
total += array[i][j];
totallength++;
}
}
return total/(totallength);
}
//майн
public static void main(String args[]) {
Scanner num = new Scanner(System.in);
System.out.println ("Введите размер матрицы ");
int size= num.nextInt();//считывает число и присваивает значение в size
System.out.println("Вы ввели размер " +size);
System.out.println("Матрица : " );
createRandomArray(size);
System.out.println("Среднее арифметическое : " );
}
}
Answer the question
In order to leave comments, you need to log in
Your double[][] da = new double[size][size] is not visible anywhere else except in the createRandomArray method.
The method must return an array in return or in parameters.
Or make da a global variable and use it in all methods, but that would be bad manners.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question