首页 > 编程知识 正文

java二维数组,java数组遍历的几种方法

时间:2023-05-05 06:42:48 阅读:19222 作者:2152

Java数组定义声明的几种方法: 1.类型名称[]变量名称=new类型名称[length];

2 .类型名称[]变量名称={? (;

3 .类型名称[]变量名称=new类型名称[]{? (;

代码示例: public class example1{ publicstaticvoidmain [ string [] args ] { /数组定义的几种方法//1 .类型名称[ ]变量名称=new类型名称[length] int []a=new int[4]; a[0]=1; a[1]=2; a[2]=3; a[3]=4; 系统. out.println (a; system.out.println(a[0]; system.out.println(a[1]; system.out.println(a[2]; system.out.println(a[3]; //2 .类型名称[]变量名称={? (; int [ ] b={ 1,2,3,4 }; system.out.println(b[0]; system.out.println(b[1]; system.out.println(b[2]; 系统. out.println (b [3]; //3 .类型名称[]变量名称=new类型名称[]{? (; int [ ] c=new int [ ] { 1,2,3,6 }; system.out.println(c[0]; system.out.println(c[1]; 系统. out.println (c [2]; 系统. out.println (c [3]; }三种方法的概述如下: 1.类型名称[]变量名称=新类型名称[length];

//1 .类型名称[]变量名称=新类型名称[length]; int []a=new int[4]; a[0]=1; a[1]=2; a[2]=3; a[3]=4; 系统. out.println (a; system.out.println(a[0]; system.out.println(a[1]; system.out.println(a[2]; system.out.println(a[3]; 方法一:

2 .类型名称[]变量名称={? (;

//2 .类型名称[]变量名称={? (; int [ ] b={ 1,2,3,4 }; system.out.println(b[0]; system.out.println(b[1]; system.out.println(b[2]; 系统. out.println (b [3]; 方法二:

3 .类型名称[]变量名称=new类型名称[]{? (;

//3 .类型名称[]变量名称=new类型名称[]{? (; int [ ] c=new int [ ] { 1,2,3,6 }; system.out.println(c[0]; system.out.println(c[1]; 系统. out.println (c [2]; 系统. out.println (c [3]; 方法:

转载于:https://www.cn blogs.com/aihua dung/p/8525267.html

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。