為什么不能這樣寫?
ublic class HelloWorld {
? ? public static void main(String[] args) {
? ? ? ??
// 定義一個長度為5的字符串數(shù)組,保存考試科目信息
String[] subjects =new String[]{0,1,2,3,4};
? ? ? ??
// 分別為數(shù)組中的元素賦值
subjects[0] = "Oracle";
subjects[1] = "PHP";
subjects[2] = "Linux";
subjects[3] = "Java";
subjects[4] = "HTML";
? ? ? ??
System.out.println("數(shù)組中第4個科目為:" +subjects[3]);
}
}
2019-07-16
要加“”
2019-05-26
public class HelloWorld {
? ? public static void main(String[] args) {
? ? ? ??
// 定義一個長度為5的字符串數(shù)組,保存考試科目信息
String[] subjects =? ? new String[]{"1","2","3","4","5"}? ? ? ?;
? ? ? ??
// 分別為數(shù)組中的元素賦值
subjects[0] = "Oracle";
subjects[1] = "PHP";
subjects[2] = "Linux";
subjects[3] = "Java";
subjects[4] = "HTML";
? ? ? ??
System.out.println("數(shù)組中第4個科目為:" +? subjects[3]? );
}
}
答:String是字符串類型,要加 “ ”
2019-05-07
String[] subjects =new String[]{0,1,2,3,4};
應該改為
String[] subjects =new String[5];