Chinaunix首页 | 论坛 | 博客
  • 博客访问: 820676
  • 博文数量: 780
  • 博客积分: 7000
  • 博客等级: 少将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-12 09:11
文章分类

全部博文(780)

文章存档

2011年(1)

2008年(779)

我的朋友
最近访客

分类:

2008-09-12 09:14:28

java中使用二维 数组

public class Array2D...{
    public static void main(String[] args)...{
        int myInt[][]=new int[5][10];
        //遍历,给数组中的每一个数组赋值
        for(int i=0;i            for(int j=0;j                myInt[i][j]=i*j;
            }
        }
        System.out.println ("myInt.length="+myInt.length+",myInt[0].length="+myInt[0].length);
        //输出数组每一维的下限和上限
        for(int i=0;i            for(int j=0;j                System.out.println ("myInt["+i+"]["+j+"]="+myInt[i][j]);
            }
        }
    }
}

 

    在中int[][] myInt是声明一个交错数组,声明二维数组是这么声明int[,] myInt,上面的代码如果换成的,需要如下表示:


    class clsArrat2D
   {
        /**////


        /// 应用程序的主入口点。
        ///

        [STAThread]
        static void Main(string[] args)
         {
            int[,] myInt=new int[5,10];
            //遍历,给数组中的每一个数组赋值
            for(int i=myInt.GetLowerBound(0);i<=myInt.GetUpperBound(0);i++)
            {
                for(int j=myInt.GetLowerBound(1);j<=myInt.GetUpperBound(1);j++)
               {
                    myInt[i,j]=i*j;
                }
            }
            //输出数组每一维的下限和上限
            for(int i=0;i           {
                Console.WriteLine("{0} {1} {2}", i, myInt.GetLowerBound(i), myInt.GetUpperBound(i));
            }
            //遍历,输出二维数组中每一个元素的个数
            for(int i=myInt.GetLowerBound(0);i<=myInt.GetUpperBound(0);i++)
            {
                for(int j=myInt.GetLowerBound(1);j<=myInt.GetUpperBound(1);j++)
                {
                    Console.WriteLine("myInt[{0},{1}]={2}",i,j,myInt[i,j]);
                }
            }
            Console.ReadLine();
        }
    }

【责编:Peng】

--------------------next---------------------

阅读(528) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~