• 第六周上机作业


    1.package finish;
    public class csy {
        public static void main(String[] args) {
             int arr [] ={10,20,30,40,50};
    
                for(int i = 0;i<arr.length;i++){
                    System.out.print(arr[i]);
                    System.out.print(" ");
                }
            }
    
        }

    
    
    2.package finish;
    public class csy {
        public static void main(String[] args) {
             int arr [] =new int[5];
             arr [0] = 10;
             arr [1] = 20;
             arr [2] = 30;
             arr [3] = 40;
             arr [4] = 50;
                for(int i = 0;i<arr.length;i++){
                    System.out.print(arr[i]);
                    System.out.print(" ");
                }
            }
    
        }
    
    
    
    3.package finish;
    public class csy {
        public static void main(String[] args) {
             
             int arr [] =new int[]{23,45,22,33,56};
               double sum=0; 
               for(int i = 0;i<arr.length;i++){
                    sum+=arr[i];
                }
                    System.out.println("最大值:"+sum);
                    System.out.println("平均值:"+sum/arr.length);
                    
            }
        }
    
    

    4.package finish;
    public class csy {
        public static void main(String[] args) {
            int[] arr = { 18, 25, 7, 36, 13, 2, 89, 63 };
            int max = arr[0];
            int maxIndex = 0;
    
            for (int i = 1; i < arr.length; i++) {
            if (max <= arr[i]) {
            max = arr[i];
            maxIndex = i;
            }
        }
            System.out.println("最大值为:" + max + "
    最大值下标为:" + maxIndex);
    
            }
        }

    5.package finish;
    public class csy {
        public static void main(String[] args) {
            int arr[] = new int[]{7,2,51,32,78,28};
            int arr2[] = new int[arr.length];
            for(int i = 0; i < arr.length; i++){
                int value = arr[arr.length-(i+1)];
                    arr2[i] = value;
                System.out.println(arr2[i]);
            }
       }
    }

    6.package finish;
    public class csy {
        public static void main(String[] args) {
            int[] arr = {5,18,28,48};
            int[] arr1 = new int[5];
            int a = 8;
            for (int i = 0; i < arr.length; i++) {
            if (arr[i] > a) {
                arr1[i] = a;
            for (i = i + 1; i < arr1.length; i++) {
                arr1[i] = arr[i - 1];
                }
            } else {
                arr1[i] = arr[i];
                }
            }
            for (int i = 0; i < 5; i++) {
                System.out.print(+arr1[i]);
                System.out.print(" ");
                }
            }
        }

     
  • 相关阅读:
    竞赛入门经典 3.2竖式问题
    竞赛入门经典 3-4竖式
    hdu 3547 (polya定理 + 小高精)
    浅入 dancing links x(舞蹈链算法)
    计算阶乘的另一些有趣的算法(转载)
    莫比乌斯反演
    STL的常用用法、函数汇总(不定时更新)
    博弈论的总结
    14年安徽省赛数论题etc.
    CCF 第六次计算机职业认证 第四题 收货 stl动态存储和fleury算法的综合应用
  • 原文地址:https://www.cnblogs.com/csy521/p/12666240.html
Copyright © 2020-2023  润新知