Array.java:
public class Array {
private double[][] recordGrade;
public Array(){
recordGrade = new double[5][2];
}
public double[][] getrecordGrade() {
return recordGrade;
}
public void setrecordGrade(double[][] recordGrade){
this.recordGrade = recordGrade;
}
ArrayTestDrive.java:
import java.util.Scanner;
import java.util.Arrays;
public class ArrayTestDrive {
@SuppressWarnings("resource")
public static void main(String[] args){
Array a = new Array();
Scanner s = new Scanner(System.in);
System.out.println("Input Grades from 0.0 to 100.00");
System.out.print("Enter grade at row[0] col[0]: ");
//a.getrecordGrade(a.setrecordGrade([0][0])) = a.getinput00() = s.nextDouble();
a.setrecordGrade([0][0]) = a.getinput00() = s.nextDouble(); //PROBLEM
问题是我不知道如何编写这段代码。我需要从另一个班级得到[0] [1]。这样我就可以为[0] [0]输入和写入一个值。
答案 0 :(得分:0)
将输入值直接分配给数组的第0行和第0列。 a.getrecordGrade()返回对数组的引用。
a.getrecordGrade()[0][0] = s.nextDouble();
答案 1 :(得分:0)
使用索引作为参数的方法:
public double getRecordGrade(int i, int y) {
return recordGrade[i][y];
}
public void setRecordGrade(int i, int y, double value){
this.recordGrade[i][y] = value;
}
然后用适当的参数调用它:
double value = s.nextDouble();
a.setrecordGrade(0, 0, value);