简体   繁体   中英

BlueJ error: incompatible types: java.lang.String cannot be converted to java.lang.String[]

Hi experts I am new to Java programming and I have decided to learn it. I am using the learning Java tutorial from the Oracle page to learn coding.

Please help me understand how to correct my code and where I went wrong

Thank you Here is my code:

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[][][] is a 3-dimension array reference type, but you're assigning a 2-dimension array to it, which is confusing the compiler. (It's expecting another array where you have "Mr. " .) Change that to String[][] year11 = { .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM