数组串写,为何报错?
String[] subjects = new String[] {Oracle,PHP,Linux,java,HtML};
System.out.println("数组中第4个科目为:" + subjects[3]);
String[] subjects = new String[] {Oracle,PHP,Linux,java,HtML};
System.out.println("数组中第4个科目为:" + subjects[3]);
2016-03-02
public class HelloWorld {
public static void main(String[] args) {
// 定义一个长度为5的字符串数组,保存考试科目信息
String[] subjects = new String[5] ;//只需要写出数组的长度就可以了
// 分别为数组中的元素赋值
subjects[0] = "Oracle";
subjects[1] = "PHP";
subjects[2] = "Linux";
subjects[3] = "Java";
subjects[4] = "HTML";//在这里已经声明了,不需要再在前面进行声明
System.out.println("数组中第4个科目为:" + subjects[3] );
}
}
举报