文章出處

 

        //一維數組定義與輸出
class  less02
{
 public static void main(String[] args) 
 {
  int stu[]=new int[]{1,2,3};   //方法一,在數據定義的時候[]里是沒有值的,因為后面已經給數組的每個元素賦值,數組的長度范圍已經確定?
  //int stu[]={1,2,3};                 方法二
  //int []stu=new int[]{1,2,3};  方法三
  //int[] stu={1,2,3};                方法四
  for(int i=0;i<stu.length;i++)
   System.out.println(stu[i]);
 }
}

//二維數組定義與輸出
class less02
{
 public static void main(String args[])
 {
  //int [][] num=new int[][]{{1,2,3},{4,5,6}};     方法一
  int [][] num={{1,2,3},{4,5,6}};                      //方法二
  for (int i=0;i<num.length ;i++ )
  {
   for (int j=0;j<num[i].length ;j++ )
   {
    System.out.print(num[i][j]+" ");
   }
   System.out.println();
  }
 }
}

文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()