• 4-9


    package practice4_9;
    
    import java.util.Arrays;
    
    /*
     * 编写数组静态赋值
     */
    public class test01 {
    
        public static void main(String[] args) {
            int[] arr1  = {10,20,30,40,50};
            System.out.println(Arrays.toString(arr1));
            /*
             * 动态赋值
             */
            int[] arr2 = new int[5];
            int a= 1;
            for (int i = 0; i < arr2.length; i++) {
                arr2[i]=a*10;
                System.out.println(arr2[i]);
                a++;
            }
            /*
             * 数组求和 平均值
             */
            int[] arr3= {23,45,22,33,56};
            int sum=0;
            for (int i = 0; i < arr3.length; i++) {
                sum+=arr3[i];
            }
            System.out.println(sum);
            int average = sum/arr3.length;
            System.out.println(average);
            /*
             * 最大值和下标记
             */
            int[] arr4 = {18,25,7,36,13,2,89,63};
            int max = arr4[0];
            int i;
            for ( i = 0; i < arr4.length; i++) {
                if (max<arr4[i]) {
                    max=arr4[i];
                }
            }
            System.out.println(max);
            for (int j = 0; j < arr4.length; j++) {
                if (max==arr4[j]) {
                    System.out.println(j);
                }
            }
        }
        
    }
  • 相关阅读:
    [LeetCode]Sort List
    [LeetCode]Single Number II
    合并两个排序的列表
    翻转链表
    链表中倒数第k个结点
    调整数组顺序使奇数位于偶数前面
    数值的整数次方
    二进制中1的个数
    矩形覆盖
    变态跳台阶
  • 原文地址:https://www.cnblogs.com/wzm7282/p/12665516.html
Copyright © 2020-2023  润新知