samedi 23 octobre 2021

'nextDouble()' in 'java.util.Random' cannot be applied to '(double)'

import java.util.Scanner;

public class HW4

        Scanner a = new Scanner(System.in);

        int rows, cols;
        double range;

        System.out.print("2차원 배열의 ROWS 수를 입력하세요 : ");
        rows = a.nextInt();
        System.out.print("2차원 배열의 COLUMNS 수를 입력하세요 : ");
        cols = a.nextInt();
        System.out.print("2차원 배열의 요소값의 최대값 입력하세요 : ");
        range = a.nextDouble();

        Matrix m2 = new Matrix(rows, cols);


        m2.aryInit(range);
        m2.aryPrint();
        System.out.println("\n");
        m2.rowAVG();
        System.out.println("\n");
        m2.colAvg();
        System.out.println("\n");
        m2.colMax();
        System.out.println("\n");
        m2.colmin();

    }

}

import java.util.Scanner;

import java.util.Random;

public class Matrix {

private double ary[][];

Matrix() {
    ary = new double[5][5];
}

public Matrix(int r, int c) {
    ary = new double[r][c];
}

public void aryInit(double range) {
    Random r = new Random();

    for (int i = 0; i < ary.length; i++) {
        for (int j = 0; j < ary[i].length; j++) {
            ary[i][j] = r.nextDouble(range);
        }
    }
}

It is an error that a is ~. ary[i][j] = r.nextDouble(range); <~ It is an error that "range" is 'nextDouble()' in 'java.util.Random' cannot be applied to '(double)'

What should I do?




Aucun commentaire:

Enregistrer un commentaire