gpt4 book ai didi

java - BlueJ 错误 : incompatible types: java. lang.String 无法转换为 java.lang.String[]

转载 作者:行者123 更新时间:2023-11-30 07:42:17 25 4
gpt4 key购买 nike

各位专家,我是 Java 编程新手,我决定学习它。我正在使用 Oracle 页面上的学习 Java 教程来学习编码。

请帮助我了解如何纠正我的代码以及哪里出了问题

谢谢这是我的代码:

public class Demo
{
public static void main(String[] args) {

String[][][] year11 ={
{"Mr. ", "Miss. "}, *// this is where i had the error: incompatible types: java.lang.String cannot be converted to java.lang.String[]*
{"James", "Jude", "Samuel",
"Sara", "Danielle", "Serah",
"David", "Natalie", "Aubrey"},
{"Year11_A", "Year10_A", "Year11_B", "Year10_A", "Year10_B"}
};
char[] aGrade = {'A', 'B', 'C', 'D', 'U'};

int[] numGrade = {100, 97, 87, 92, 67, 71, 56, 66, 87};

System.out.println("Name:" + year11[0][0] + "Result: " + numGrade[4] +
"Grade: " + aGrade[3]);
System.out.println("Name:" + year11[0][1] + "Result: " + numGrade[3] +
"Grade: " + aGrade[0]);
System.out.println("Name:" + year11[0][2] + "Result: " + numGrade[2] +
"Grade: " + aGrade[1]);
System.out.println("Name:" + year11[1][3] + "Result: " + numGrade[8] +
"Grade: " + aGrade[1]);
System.out.println("Name:" + year11[1][4] + "Result: " + numGrade[5] +
"Grade: " + aGrade[2]);
System.out.println("Name:" + year11[1][5] + "Result: " + numGrade[2] +
"Grade: " + aGrade[2]);
System.out.println("Name:" + year11[0][6] + "Result: " + numGrade[1] +
"Grade: " + aGrade[1]);
System.out.println("Name:" + year11[1][7] + "Result: " + numGrade[6] +
"Grade: " + aGrade[3]);
System.out.println("Name:" + year11[1][8] + "Result: " + numGrade[7] +
"Grade: " + aGrade[3]);

}

}

最佳答案

String[][][] 是一个 3 维数组引用类型,但您要为其分配一个 2 维数组,这会让编译器感到困惑。 (它需要另一个数组,其中包含 “Mr.”。)将其更改为 String[][]year11 = {

关于java - BlueJ 错误 : incompatible types: java. lang.String 无法转换为 java.lang.String[],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34482147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com