2015年5月12日 星期二

Java : Arrarys

Arrays in Java are also objects.we use the following syntax:
int[ ] arry; // There is no size

We create new size like below
arry = new int[5]



To show array length

arry.length


To see the array value

int[ ] arry = { 1, 2, 3, 4, 5}
or 
arry[1] = 20;

Here is example code :





public class Demo {
           public static void main(String[ ] args) {
                  int[ ] arry ;

                  arry = new int[5];
                  arry[0] = 33;
                  arry[1] = 34;
                  arry[2] = 35;
                  arry[3] = 36;
                  arry[3] = 37;    
  
                  for ( int i = 0; i < arry.length; i++)

                  {
                         System.out.println(arry[i]);
                  }
 
                  
           }
}

沒有留言:

張貼留言