• 第六周上机练习


    1.

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

    2.

    package test;
    
    public class LH {
    
        public static void main(String[] args) {
            int a[]= new int[5];
            a[0]=10;
            a[1]=20;
            a[2]=30;
            a[3]=40;
            a[4]=50;
            for(int i=0;i<a.length;i++) {
                System.out.println(a[i]);
            }
        }
        
        }

    3.

    package test;
    
    public class LH {
    
        public static void main(String[] args) {
            int a[]= {23,45,22,33,56};
            double sum=0;
            for(int i=0;i<a.length;i++) {
                sum+=a[i];
            }
            System.out.println("和"+sum+" 平均值"+sum/5);
            }
        }

    4.

    package test;
    public class LH {
          public static void main(String[] args) {
                Scanner input = new Scanner(System.in);
                int[] arr = {18,25,7,36,13,2,89,63};
                int max =arr[0];
                int index =0;
                for(int i =1;i<arr.length;i++) {
                    if(max < arr[i]) {
                        max = arr[i];
                        index=i;
                    }
                }
                System.out.println("max="+max+" 下标"+index);
              }
    
          }

    5.

    package test;
    public class LH {
    
        public static void main(String[] args) {
            int num[] = new int[] { 1, 2, 3, 4, 5, 7 };
            int num1[] = new int[num.length];
            int index = 0;
            for (int i = num.length - 1; i >= 0; i --) {
            num1[index] = num[i];
            index ++;
            }
            num = num1;
            for(int n:num){
            System.out.println(n);
            }
        }
    }
  • 相关阅读:
    box布局中文字溢出问题
    清除浮动
    react状态提升问题::::
    React两三事
    java直接调用kmeans聚类
    java实现文本词频统计
    java 中list.toArray方法的使用
    java中Map<String,Double>map按照value降序排列
    和声搜索算法java实现
    java 自动打开浏览器并点击
  • 原文地址:https://www.cnblogs.com/z118127/p/12666138.html
Copyright © 2020-2023  润新知