INT []不能被转换成int [英] int [] cannot be converted to int

查看:170
本文介绍了INT []不能被转换成int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个二维数组的成绩册方法,它有学生姓名,然后是考试成绩。在课堂上,我有如下:

 私人诠释numberOfStudents;
私有String [] studentName;
私人诠释examNumber;
私人诠释[] examScores;
私人INT [] []成绩册;公共ExamAverage()
{
numberOfStudents = 0;
studentName =新的String [numberOfStudents]
examNumber = 0;
examScores =新INT [numberOfStudents]
成绩册=新INT [numberOfStudents] [examScores];

不过,我得到一个错误INT []不能转换成int。


解决方案

您有:

  =成绩册新INT [numberOfStudents] [examScores];

examScores INT [] 。阵列的尺寸必须是一个 INT ,所以 examScores 不能用作数组维(我能理解你的困惑错误,因为它是多么的文字:它想要一个 INT ,但是你给它一个 INT [] )<。 / p>

通过你的描述来看我猜你的意思线沿线的东西更多:

  =成绩册新INT [numberOfStudents] [numberOfExams];

其中, numberOfExams INT 你需要,包括考试的次数。只是一个猜测,但。

I want to use a 2D array for a gradebook method, where it has the student names, then the exam scores. In the class I have as follows.

private int numberOfStudents;    
private String [] studentName;
private int  examNumber;
private int [] examScores;
private int [][] gradebook;

public ExamAverage ()
{
numberOfStudents = 0;
studentName = new String[numberOfStudents];
examNumber = 0;
examScores = new int [numberOfStudents]; 
gradebook = new int [numberOfStudents][examScores];

Yet I get an error int[] cannot be converted to int.

解决方案

You have:

gradebook = new int [numberOfStudents][examScores];

But examScores is an int[]. Array dimensions have to be an int, so examScores cannot be used as an array dimension (I can understand your confusion about the error, given how literal it is: it wants an int but you gave it an int[]).

Judging by your description I'm guessing you mean something more along the lines of:

gradebook = new int [numberOfStudents][numberOfExams];

Where numberOfExams is an int you'll need, containing the count of exams. Just a guess, though.

这篇关于INT []不能被转换成int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆