zoukankan      html  css  js  c++  java
  • 数组的静态初始化

     1 package day04;
     2 
     3 public class ArrayStaticDemo {
     4     public static void main(String[] args) {
     5         //数组静态初始化:初始化的时候指定每个元素的初始值,由系统决定数组长度
     6         //完整格式:数据类型 [] 数组名 = new 数据类型 [] {数据1,数据2,数据3……}
     7         int[] arr = new int[]{1, 2, 3, 4};
     8         System.out.println(arr[0]);
     9         System.out.println(arr[1]);
    10         System.out.println(arr[2]);
    11         System.out.println(arr[3]);
    12         System.out.println("----------");
    13         //简化格式:数组类型 [] 数组名 = {数据1,数据2,数据3……}
    14         int[] arr1 = {11, 22, 33, 44};
    15         System.out.println(arr1[0]);
    16         System.out.println(arr1[1]);
    17         System.out.println(arr1[2]);
    18         System.out.println(arr1[3]);
    19     }
    20 }

    执行结果:

    欢迎批评指正,提出问题,谢谢!
  • 相关阅读:
    Python之socket_tcp
    Python之多进程&异步并行
    Qt forever关键字
    Qt程序在XP系统上不能正常运行
    Qt多线程的使用
    QScrollArea
    QtoolButton
    QComboBox
    Qt播放音频文件
    Qt5.9.1编译oracle驱动
  • 原文地址:https://www.cnblogs.com/xxeleanor/p/14212057.html
Copyright © 2011-2022 走看看