weixin_慕田峪3239053
2018-12-07 12:12
ublic class HelloWorld {
public static void main(String[] args) {
// 定义一个长度为5的字符串数组,保存考试科目信息
String[] subjects =new String[]{0,1,2,3,4};
// 分别为数组中的元素赋值
subjects[0] = "Oracle";
subjects[1] = "PHP";
subjects[2] = "Linux";
subjects[3] = "Java";
subjects[4] = "HTML";
System.out.println("数组中第4个科目为:" +subjects[3]);
}
}
要加“”
public class HelloWorld {
public static void main(String[] args) {
// 定义一个长度为5的字符串数组,保存考试科目信息
String[] subjects = new String[]{"1","2","3","4","5"} ;
// 分别为数组中的元素赋值
subjects[0] = "Oracle";
subjects[1] = "PHP";
subjects[2] = "Linux";
subjects[3] = "Java";
subjects[4] = "HTML";
System.out.println("数组中第4个科目为:" + subjects[3] );
}
}
答:String是字符串类型,要加 “ ”
String[] subjects =new String[]{0,1,2,3,4};
应该改为
String[] subjects =new String[5];
Java入门第一季(IDEA工具)升级版
1165174 学习 · 17581 问题
相似问题