暴躁的田

导航

第四次上机作业

package com.xuexiao;

public class Text7 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        //数组长度为五的静态赋值
        int[] arr = {1,2,3,4,5,6};
        for(int i=0;i<arr.length;i++) {
            System.out.println(arr[i]);
        }
    }

}

 

 

package com.xuexiao;

import java.util.Scanner;

public class Text7 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        //动态赋值5 输出
        int[] arr = new int [5];
        Scanner sc= new Scanner(System.in);
        int i;
        for(i = 0;i<arr.length;i++) {
            System.out.println("请赋值"+(i+1)+"数:");
            arr[i] = sc.nextInt();
            
            }
        System.out.print("结果为:[");
        for(int j= 0;j<arr.length;j++) {
            System.out.print(arr[j]+" ");
        }System.out.println("]");
}
        }

 

 

package com.xuexiao;

import java.util.Scanner;

public class Text7 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        //整型数组 {23 45 22 33 56}
        float sum = 0;
        int[] arr = {23,45,22,33,56};
        for(int i =0;i<arr.length;i++) {
            
            sum+= arr[i];
            
        }System.out.println("和为:"+sum);
        System.out.println("平均数为:"+sum/arr.length);
}
        }

 

 

package com.xuexiao;

//import java.util.Scanner;

public class Text7 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        //8个整数 {18 25 7 36 13 2 89 63}
        
        int[] arr = {18,25,7,36,13,2,89,63};
        int max = arr[0];
        int i;
        int s=0;
        for(i = 1;i<arr.length;i++) {
            if(arr[i]>max) {
            max = arr[i];
            s=i;
            }
        }
        System.out.println("最大值为:"+max);
        System.out.println("角标为"+s);
}
        }
        

 

 

package com.xuexiao;

import java.util.Scanner;

public class Text7 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int[] arr = new int [5];
        Scanner sc= new Scanner(System.in);
        int i;
        for(i = 0;i<arr.length;i++) {
            System.out.println("请赋值"+(i+1)+"数:");
            arr[i] = sc.nextInt();
            
            }
        System.out.print("结果为:[");
        for(int j= arr.length-1;j >= 0;j--) {
            System.out.print(arr[j]+" ");
        }System.out.println("]");
}
        }
        

 

posted on 2020-04-09 11:55  田智源  阅读(199)  评论(0编辑  收藏  举报