zoukankan      html  css  js  c++  java
  • 数组

    数组的基本要素

    标识符(和变量一样,用于区分不同的数组)

    数组元素(数组标识符后,要向数组中存放数据)

    数组下标(对数组进行编号,根据编号去存取)

    元素类型(存储在数组中的数组元素应该是同一数据类型)

    使用数组的步骤

    (1)声明数组

    (2)分配空间

    (3)赋值

    (4)对数据进行处理

    数组的语法

    数据类型[] 数组名 = {值}; || 数据类型[] 数组名 = new 数据类型[]{值};

    数组的运用

    public class f{
        public static void main(String[] args){
            String[] goods = new String[]{"Nike背包","Adidas运动衫",
                    "李宁运动鞋","Kappa外套","361腰包"};
            System.out.println("本次活动特价商品有:");
            for(int i = 0; i < goods.length; i++){
                System.out.println(goods[i]);
            }
        }
    }
    代码示例如下

    运行结果示例如下所示

    数组排序的语法

    Arrays.sort(数组名);

    数组排序的运用

    import java.util.Arrays;
    import java.util.Scanner;
    public class g{
        public static void main(String[] args){
            int[] scores = new int[5];
            Scanner input = new Scanner(System.in);
            System.out.println("请输入5位学员的成绩:");
            for(int i = 0; i < scores.length; i++){
                scores[i] = input.nextInt();
            }
            Arrays.sort(scores);
            System.out.println("学员成绩按升序排列:");
            for(int i = 0; i < scores.length; i++){
                System.out.print(scores[i]+"	" );
                
            }
        }
    }
    代码示例如下

    运行结果示例如下所示

  • 相关阅读:
    Python实现日志分析并转成excel
    dockerfile案例 springboot项目部署
    1、springboot启动加载不到src/main/resources下的配置文件application.yml
    [Dockerfile构建镜像]
    dockerfile案例 centos
    dockerfile语法
    dockerfile 笔记202110622
    docker 数据卷 挂载共享
    docker 国内镜像加速aliyun
    微信公众号 几种移动端UI框架介绍
  • 原文地址:https://www.cnblogs.com/daixiumei/p/6953894.html
Copyright © 2011-2022 走看看