侧边栏壁纸
  • 累计撰写 53 篇文章
  • 累计收到 5 条评论

Chapter 06

bbchen
2022-09-15 / 1 评论 / 6 阅读 / 正在检测是否收录...

数组

image-20220827172637281

练习:

image-20220827173036948

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] + " ");
        }
    }
}            

image-20220827173852243

image-20220827173908916

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);
    }
}
数组赋值默认为引用传递,赋的值是地址
0

评论

博主关闭了所有页面的评论