• 第四次上机作业


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

  • 相关阅读:
    linux机器,docker安装mysql
    一次完整的http请求过程
    mac 安装git
    mac下安装maven和IntelliJ IDEA
    小米老手机 安装charles的https证书 MI NOTE LTE
    mac搭建node环境
    python&kafka集群取消息
    mac电脑破解pycharm
    pytest安装
    sql group by 和 定义输出的小数位数
  • 原文地址:https://www.cnblogs.com/tianzhiyuan/p/12665916.html
Copyright © 2020-2023  润新知