返回列表 發帖

陣列的長度

利用length屬性, 可取得陣列的長度, 即該陣列包含了幾位成員.

int a[]={1,2,3,4};
int b[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
int c[][][]={{{1,2,3,4},{1,2,3,4},{1,2,3,4}},{{1,2,3,4},{1,2,3,4},{1,2,3,4}}};


上列三個陣列長度分別為何呢?
  1. public class Ch41
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         int a[]={1,2,3,4};
  6.         int b[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
  7.         int c[][][]={{{1,2,3,4},{1,2,3,4},{1,2,3,4}},{{1,2,3,4},{1,2,3,4},{1,2,3,4}}};
  8.         System.out.println(a.length);     //4
  9.         System.out.println(b.length);     //3
  10.         System.out.println(c.length);     //2
  11.     }
  12. }
複製代碼

  1. public class ch01
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         int a[]={1,2,3,4};
  6.         int b[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
  7.         int c[][][]={{{1,2,3,4},{1,2,3,4},{1,2,3,4}},{{1,2,3,4},{1,2,3,4},{1,2,3,4}}};
  8.         System.out.println(a.length);
  9.         System.out.println(b.length);
  10.         System.out.println(c.length);
  11.     }
  12. }
複製代碼

TOP

  1. public class Ch01
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         int a[]={1,2,3,4};
  6.         int b[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
  7.         int c[][][]={{{1,2,3,4},{1,2,3,4},{1,2,3,4}},{{1,2,3,4},{1,2,3,4},{1,2,3,4}}};
  8.         
  9.         System.out.println(a.length);     
  10.         System.out.println(b.length);     
  11.     }
  12. }
複製代碼

TOP

  1. public class Ch02
  2. {
  3.     public static void main(String args[])
  4.     {
  5.             int a[]={1,2,3,4};
  6.             int b[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
  7.             int c[][][]={{{1,2,3,4},{1,2,3,4},{1,2,3,4}},{{1,2,3,4},{1,2,3,4},{1,2,3,4}}};               
  8.             System.out.println(a.length);    //4
  9.             System.out.println(b.length);    //3
  10.             System.out.println(c.length);    //2


  11.     }
  12. }
複製代碼

TOP

  1. public class Ch01
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         int a[]={1,2,3,4};
  6.         int b[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
  7.         int c[][][]={{{1,2,3,4},{1,2,3,4},{1,2,3,4}},{{1,2,3,4},{1,2,3,4},{1,2,3,4}}};
  8.         System.out.println(a.length);     
  9.         System.out.println(b.length);     
  10.         System.out.println(c.length);     
  11.     }
  12. }
複製代碼

TOP

  1. import java.util.Scanner;

  2. public class Ch05 {

  3.         public static void main(String[] args)
  4.         {
  5.         int a[]={1,2,3,4};
  6.         int b[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
  7.         int c[][][]={{{1,2,3,4},{1,2,3,4},{1,2,3,4}},{{1,2,3,4},{1,2,3,4},{1,2,3,4}}};
  8.         System.out.println(a.length);
  9.         System.out.println(b.length);
  10.         System.out.println(c.length);
  11.         }
  12.      }
複製代碼

TOP

  1. public class Ch00
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         int a[]={1,2,3,4};        
  6.             int b[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
  7.             int c[][][]={{{1,2,3,4},{5,6,7,8},{9,10,11,12}},
  8.                      {{13,14,15,16},{17,18,19,20},{21,22,23,24}}};
  9.             System.out.println(a.length);
  10.             System.out.println(b.length);
  11.             System.out.println(c.length);

  12.     }
  13. }
複製代碼

TOP

  1. public class CH10
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         int a[]={1,2,3,4};
  6.         int b[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
  7.         int c[][][]={{{1,2,3,4},{1,2,3,4},{1,2,3,4}},{{1,2,3,4},{1,2,3,4},{1,2,3,4}}};
  8.         System.out.println(a.length);
  9.         System.out.println(b.length);
  10.         System.out.println(c.length);
  11.     }
  12. }
複製代碼

TOP

  1. import java.util.Scanner;


  2. public class Ch123 {
  3.         public static void main(String[] args) {
  4.                 int a[]={1,2,3,4};
  5.                 int b[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
  6.                 int c[][][]={{{1,2,3,4},{1,2,3,4},{1,2,3,4}},{{1,2,3,4},{1,2,3,4},{1,2,3,4}}};
  7.     System.out.println(a.length);
  8.     System.out.println(b.length);
  9.     System.out.println(c.length);}
  10. }

  11.        
複製代碼

TOP

  1. public class Ch01
  2. {
  3.         public static void main(String args[])
  4.         {
  5.                 int a[]={1,2,3,4};
  6.                 int b[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
  7.                 int c[][][]={{{1,2,3,4},{1,2,3,4},{1,2,3,4}},{{1,2,3,4},{1,2,3,4},{1,2,3,4}}};
  8.                 System.out.println(a.length);
  9.                 System.out.println(b.length);
  10.                 System.out.println(c.length);
  11.         }
  12. }
複製代碼

TOP

  1. package Ch01;

  2. import java.util.Scanner;

  3. public class Ch01 {
  4.         public static void main(String args[])
  5.         {
  6.                 int a[]={1,2,3,4};
  7.         int b[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
  8.         int c[][][]={{{1,2,3,4},{1,2,3,4},{1,2,3,4}},{{1,2,3,4},{1,2,3,4},{1,2,3,4}}};
  9.         System.out.println(a.length);
  10.         System.out.println(b.length);
  11.         System.out.println(c.length);
  12.         }

  13. }
複製代碼

TOP

  1. public class Ch3333333
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         int a[]={1,2,3,4};
  6.         int b[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
  7.         int c[][][]={{{1,2,3,4},{1,2,3,4},{1,2,3,4}},{{1,2,3,4},{1,2,3,4},{1,2,3,4}}};
  8.         System.out.println(a.length);     //4
  9.         System.out.println(b.length);     //3
  10.         System.out.println(c.length);     //2
  11.     }
  12. }
複製代碼

TOP

  1. public class Ch14
  2. {
  3.     public static void main(String args[])
  4.     {
  5.             int a[]={1,2,3,4};
  6.             int b[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
  7.             int c[][][]={{{1,2,3,4},{1,2,3,4},{1,2,3,4}},{{1,2,3,4},{1,2,3,4},{1,2,3,4}}};
  8.              System.out.println(a.length);     
  9.          System.out.println(b.length);     
  10.          System.out.println(c.length);

  11.               }   
  12.       
  13.       
  14.     }
複製代碼

TOP

  1. public class Ch41 {

  2.         public static void main(String[] args) {
  3.                 int a[]={1,2,3,4};
  4.         int b[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
  5.         int c[][][]={{{1,2,3,4},{1,2,3,4},{1,2,3,4}},{{1,2,3,4},{1,2,3,4},{1,2,3,4}}};
  6.         System.out.println(a.length);
  7.         System.out.println(b.length);
  8.         System.out.println(c.length);

  9.         }

  10. }
複製代碼

TOP

  1. public class Ch01
  2. {
  3.         public static void main(String args[])
  4.         {        
  5.                 int a[]={1,2,3,4};
  6.         int b[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
  7.         int c[][][]={{{1,2,3,4},{1,2,3,4},{1,2,3,4}},{{1,2,3,4},{1,2,3,4},{1,2,3,4}}};
  8.         System.out.println(a.length);     
  9.         System.out.println(b.length);     
  10.         System.out.println(c.length);            
  11.         }
  12. }
複製代碼

TOP

  1. public class Ch01
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         int a[]={1,2,3,4};
  6.         int b[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
  7.         int c[][][]={{{1,2,3,4},{1,2,3,4},{1,2,3,4}},{{1,2,3,4},{1,2,3,4},{1,2,3,4}}};
  8.         System.out.println(a.length);     
  9.         System.out.println(b.length);     
  10.         System.out.println(c.length);     
  11.     }
  12. }
複製代碼

TOP

  1. public class Ch15 {

  2.         public static void main(String[] args)
  3.         {
  4.                 int a[]={1,2,3,4};
  5.                 int b[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
  6.                 int c[][][]={{{1,2,3,4},{1,2,3,4},{1,2,3,4}},{{1,2,3,4},{1,2,3,4},{1,2,3,4}}};
  7.          
  8.                System.out.println(a.length);
  9.                System.out.println(b.length);
  10.                System.out.println(c.length);
  11.         }
  12. }
複製代碼

TOP

  1. public class Ch30 {

  2.         public static void main(String[] args) {
  3.        
  4.                 int a[]={1,2,3,4};
  5.         int b[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
  6.                 int c[][][]={{{1,2,3,4},{5,6,7,8},{9,10,11,12}},
  7.                                 {{13,14,15,16},{17,18,19,20},{21,22,23,24}}};
  8.                 System.out.println(a.length);     
  9.         System.out.println(b.length);     
  10.         System.out.println(c.length);     

  11.         }

  12. }
複製代碼

TOP

  1. public class ch01
  2. {
  3.     public static void main(String args[])
  4.     {
  5.             int a[]={1,2,3,4};
  6.             int b[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
  7.             int c[][][]={{{1,2,3,4},{1,2,3,4},{1,2,3,4}},{{1,2,3,4},{1,2,3,4},{1,2,3,4}}};
  8.             System.out.println(a.length);
  9.             System.out.println(b.length);
  10.             System.out.println(c.length);
  11.     }
  12. }
複製代碼
我好帥
我超級帥
我非常的帥
我宇宙第一帥

TOP

  1. public class Ch87 {

  2.         public static void main(String[] args) {
  3.    
  4.                 int a[]={1,2,3,4};
  5.                 int b[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
  6.                 int c[][][]={{{1,2,3,4},{1,2,3,4},{1,2,3,4}},{{1,2,3,4},{1,2,3,4},{1,2,3,4}}};
  7.                
  8.        
  9.                 System.out.println(a.length);
  10.                 System.out.println(b.length);
  11.                 System.out.println(c.length);
  12.                
  13.                
  14.                     }               
  15.                
  16.         }
複製代碼

TOP

返回列表