4.9上机作用

1.

package www;
import java.util.Scanner;
public class test{

    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 www;
import java.util.Scanner;
public class test{

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

3.

package www;
import java.util.Scanner;
public class test{

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

 

 

4.

package www;
import java.util.Scanner;
public class test{

    public static void main(String[] args) {
    int[]arr={18,25,7,36,13,2,89,63 };
    int max=arr[0];
    int index=0;
    for(int i=0;i<arr.length;i++){
        if(max<arr[i]){
            max=arr[i];
            index=i;
        }
    }
    System.out.println("最大数是"+max+"下标是"+index)    ;
        }
    
    }
    

 

posted @ 2020-04-09 11:04  余归-  阅读(110)  评论(0编辑  收藏  举报