1

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]);

    }

}
4
  • 2
    change your array from 3D to 2D like String[][] year11 Commented Dec 27, 2015 at 16:04
  • 1
    {"foo","bar"} is one dimensional array. How many dimensions we need for {{"a","b"},{"c","d"}}? Commented Dec 27, 2015 at 16:07
  • Possibly off topic, but BlueJ has some strange behaviours that are different from standard jdks, so I would not actually recommend using it. (This has nothing to do with your question, but rather serves as a general comment) Commented Dec 27, 2015 at 16:19
  • Please can you inform me the best JDK to use to learn for a beginner. Thank you Commented Dec 27, 2015 at 16:52

1 Answer 1

1

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 = {.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.