java数组的定义,取值,遍历


package com.company;

public class Main {

public static void main(String[] args) {
//int[] s={1,2,3};//定义数组直接赋值
//int [] a = new int[]{10,5};//跟上一种一样,上一种是这种的的简写。
// int [] c =new int[2];
//没有给定义的数组的赋值,[2]中的2是这个数组的长度(lenght)为2.
//c[0] =1;//给c的第一个(0为索引 java中的索引从0开始)数赋值
// c[1] =2;//给c的第二个数赋值


//如何在定义的数组中取出所需要的值。
//String [] strname=new String[3];
// strname[0]="彭于晏";
// strname[1]="黄绍黎";
//strname[2]="胡歌";
// System.out.println(strname[1]);//这种取值只能取其中的一个数

//如何把里面的值都取出来呢?那就用遍历,用循坏语句。
String [] strname=new String[3];
strname[0]="彭于晏";
strname[1]="黄绍黎";
strname[2]="胡歌";
for(int i=0;i<strname.length ;i++){
System.out.println(strname[i]);


}


}
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM