-2

package Exercises;

public class Challenge9 {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    //create class instance
    Challenge9 al = new Challenge9();
    
    //call the first method
    //al.returnAlphabetArray();
    
    //call second method
        char[] A = al.getAlphabetArray();
        System.out.println("The letters of the alphabet are: " + A);
}
//public void returnAlphabetArray() {
    //System.out.println("Read the alphabet");
//}
public char[] getAlphabetArray() { //create first method
    char[] letters = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
    return letters;
}

}

I want to display the letters of the alphabet but why am I getting this output after the string: "[C@3d012ddd" ?

angel
  • 1
  • 1

1 Answers1

0

if you don't want to hard code the alphabet

public char[] getAlphabetArray() {
        char[] letters = new char[122 - 97];
        for (int i = 0; i < letters.length; i++) {
            letters[i] = (char) (97 + i);
        }
        return letters;
    }

And use this to print an array

Arrays.toString(getAlphabetArray())