• 第七次作业


    //1.编写一个简单程序,要求数组长度为5,静态赋值10,20,30,40,50,在控制台输出该数组的值.
    package com.a01;
    
    public class hellowold {
        public static void main(String[] args) {
    
            int[] a = { 10, 20, 30, 40, 50 };
            System.out.println(a[0]);
            System.out.println(a[1]);
            System.out.println(a[2]);
            System.out.println(a[3]);
            System.out.println(a[4]);
        }
    }
    //2.编写一个简单程序,要求数组长度为5,动态赋值10,20,30,40,50,在控制台输出该数组的值。
    package com.a01;
    
    public class hellowold {
        public static void main(String[] args) {
            int[] a = { 10, 20, 30, 40, 50 };
            for (int i = 0; i < 5; i++) {
                System.out.println(a[i]);
            }
        }
    }
    //3.编写一个简单程序,定义整型数组,里面的元素是{23,45,22,33,56},求数组元素的和、平均值
    package com.a01;
    
    public class hellowold {
        public static void main(String[] args) {
            int[] n = { 23, 45, 22, 33, 56 };
            double sum = 0;
            for (int i = 0; i < 5; i++) {
                sum += n[i];
            }
            double y = sum / 5;
            System.out.println("和为:" + sum + "平均值为:" + y);
        }
    }
    //4.在一个有8个整数(18,25,7,36,13,2,89,63)的数组中找出其中最大的数及其下标。
    package com.a01;
    
    public class hellowold {
        public static void main(String[] args) {
            int[] k = { 18, 25, 7, 36, 13, 2, 89, 63 };
            int max = k[0];
            int a = 0;
            for (int i = 0; i < k.length; i++) {
                if (k[i] > max) {
                    max = k[i];
                    a = i + 1;
                }
            }
            System.out.println(" 最大为:" + max + "  下标为:" + a);
        }
    }
    //5. 将一个数组中的元素逆序存放(知识点:数组遍历、数组元素访问)
    package com.a01;
    
    public class hellowold {
        public static void main(String[] args) {
            int[] a = new int[] { 1, 3, 2, 5, 8 };
            int t;
            for (int i = 0; i < a.length / 2; i++) {
                t = a[i];
                a[i] = a[a.length - 1 - i];
                a[a.length - 1 - i] = t;
            }
            for (int i = 0; i < a.length; i++) {
                System.out.print(a[i] + ", ");
            }
        }
    }
    6、有一个已经排好序的数组。现输入一个数,要求按原来的规律将它插入数组中。(附加题)
  • 相关阅读:
    7年.NET面试Java的尴尬历程
    服务挂后Dump日志
    并发中如何保证缓存DB双写一致性(JAVA栗子)
    如何通过Visual Studio来管理我们的数据库项目
    无需Get更多技能,快速打造一个可持久化的任务调度
    Dapper Use For Net
    2014年——新的开始,新的人生
    途牛网站无线架构变迁实践
    windows 下解决 Time_Wait 和 CLOSE_WAIT 方法
    System.Data.DbType 与其它DbType的映射关系
  • 原文地址:https://www.cnblogs.com/hyonf/p/12666058.html
Copyright © 2020-2023  润新知