package com.karl1; //动态初始化:适合开始不确定具体元素值,只知道元素个数的业务场景 //静态初始化:适合一开始就知道存入哪些元素值的业务场景 public class ArrayDemo3 { public static void main(String[] args) { //动态初始化数组 //数据类型[] 数组名=new 数据类型[长度] int[] age=new int[3]; System.out.println(age[0]); System.out.println(age[1]); System.out.println(age[2]); //后赋值 age[0]=12; age[1]=18; age[2]=32; System.out.println(age[0]); System.out.println(age[1]); System.out.println(age[2]); System.out.println("--------------------------------------------"); //不同数据类型的默认值 char[] chars=new char[3]; System.out.println((int) chars[0]);//转化成int类型 System.out.println((int) chars[2]); double[] doubll=new double[80]; System.out.println(doubll[0]); System.out.println(doubll[79]); boolean[] flag=new boolean[100]; System.out.println(flag[0]); System.out.println(flag[99]); String[] name=new String[80]; System.out.println(name[0]); System.out.println(name[79]); } }
标签:初始化,静态,age,System,println,new,动态,out From: https://www.cnblogs.com/Karl-hut/p/17437940.html