数组
练习:
public class ArrayExercise01 {
public static void main(String[] args) {
char[] letter = new char[26];
for (int i = 0; i < letter.length; i++) {
letter[i] = (char)('A' + i); // 强制类型转换
}
for (int j = 0; j < letter.length; j++) {
System.out.print(letter[j] + " ");
}
}
}
public class ArrayExercise02 {
public static void main(String[] args) {
int[] array = {4, -1, 9, 10, 23};
int maxNum = array[0];
int index = 0;
for (int i = 1; i < array.length; i++) {
if(array[i] > maxNum){
maxNum = array[i];
index = i;
}
}
System.out.println("Max number is: " + maxNum +
", it\'s index is " + index);
}
}
数组赋值默认为引用传递,赋的值是地址
评论