我在將數據交互輸入到數組時遇到問題。我試圖使用nextLine方法將一組12個名稱添加到數組中,但是當我在第12行的末尾進行編譯時,它給了我錯誤「不兼容類型」。嘗試向數組輸入數據時不兼容的類型
public class nextLineArray {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
char names[] = new char[12];
System.out.println("Enter the 12 names: ");
for(int i = 0; i < 12; i++) {
names[i] = input.nextLine();
}
System.out.println(names);
}
}
input.nextLine()返回什麼?你的'name'數組包含什麼? –
你真的想代表個人名字嗎?我想你希望你的數組是String類型的,而不是char。 – csmckelvey