第四次上机作业

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) {
            System.out.println(arr[i]);
        }
    }

}

第四次上机作业_第1张图片

 

 

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) {
            System.out.println("请赋值"+(i+1)+"数:");
            arr[i] = sc.nextInt();
            
            }
        System.out.print("结果为:[");
        for(int j= 0;j) {
            System.out.print(arr[j]+" ");
        }System.out.println("]");
}
        }

第四次上机作业_第2张图片

 

 

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) {
            
            sum+= arr[i];
            
        }System.out.println("和为:"+sum);
        System.out.println("平均数为:"+sum/arr.length);
}
        }

第四次上机作业_第3张图片

 

 

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) {
            if(arr[i]>max) {
            max = arr[i];
            s=i;
            }
        }
        System.out.println("最大值为:"+max);
        System.out.println("角标为"+s);
}
        }
        

第四次上机作业_第4张图片

 

 

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) {
            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("]");
}
        }
        

第四次上机作业_第5张图片

 

你可能感兴趣的:(第四次上机作业)