第六周上机练习

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);
        }
    }
}

 

posted @ 2020-04-09 12:42  计算机1804梁浩  阅读(137)  评论(0编辑  收藏  举报