我希望读取int值并创建一个新数组,其中的char值对应于每个int值。有人能给我指明正确的方向吗?或者推荐一些东西给我学习/阅读吗?
我想不通该怎么写。这是我迄今为止所拥有的。
int[][] Grades = {{90, 54, 32, 25}, {65, 80, 72, 26}};
for (int i = 0; i < Grades.length; i++) {
for (int j = 0; j < Grades[i].length; j++) {
if (Grades[i][j] >= 90) {
}
if (Grades[i][j] >= 80) {
}
if (Grades[i][j] >= 70) {
}
if (Grades[i][j] >= 60) {
} else {
}
System.out.print(Grades[i][j] + "t");
}
}
}
}
声明一个二维char
数组并保存相应的等级字符。
int[][] Grades = {{90, 54, 32, 25}, {65, 80, 72, 26}};
char[][] result=new char[Grades.length][4];
for (int i = 0; i < Grades.length; i++) {
for (int j = 0; j < Grades[i].length; j++) {
if (Grades[i][j] >= 90) {
result[i][j]='A';
}
....
}
}
您可以用这种方式创建字符数组,
char output[][] = new char[Grades.length][4];
并以这种方式为其赋值,
output[i][j] = 'A';
您必须使用"else-if"。
char[][] r = new char[Grades.length][4];
for (int i = 0; i < Grades.length; i++) {
for (int j = 0; j < Grades[i].length; j++) {
if (Grades[i][j] >= 90) {
r[i][j] = 'A';
}
else if (Grades[i][j] >= 80) {
r[i][j] = 'B';
}
else if (Grades[i][j] >= 70) {
r[i][j] = 'C';
}
这一切都在一个函数中吗?我认为应该构建一个新的二维char数组,然后从函数返回。将二维int数组作为参数。