Skip to main content
Array in java

Array is a variable that can hold
more than one value at a time.

Declaration :
   int arr[] = {elements}
   or
   int [] arr = {elements}

Intialization :
   int arr[] = {2, 4, 6, 7,}
 
  Example :

   public class arrLesson {
       
       public static void main(String           args[]) {
               // declares an array
               int arr[] = { 2, 3, 2, 9, 3 };
             
                  for(int i=0; i < arr.length;       i++)      {   
                  /* outputs each element
                      of the array */
                 System.out.println( arr[i] );
              }
 

        }

}

result :
2
3
2
9
3

Comments

Popular posts from this blog

Java if else statement     If else statement is a conditional statement that executes a block of code once the condition is true otherwise  executes else block if the condition becomes false.    Syntax :             if (condition) {                   //  code to execute              } else {                      //  code to execute                   }     Example :         public class conditionalProg {                    public static void     main(String args[]) {                    /* declaration and                   ...

Method Overloading in Java Best Example For Biggeners and Students.

class  plus{   static   int  add( int  a, int  b) {     return  a+b; }      static   int  add( int  a, int  b, int  c)     {       return  a+b+c;    }   }   class  Overloading1 {   public   static   void  main(String[] args)    {         //access the add method with 2 param from class plus,      //pass 2 arguments and print the return value      System.out.println (plus.add( 10 , 10 ));         //access the add method with 3 param from class plus,        //pass  3 arguments and print the return value       System.out.println (plus.add( 10 , 10 , 10 ));       } }   It will produce the following results: 20 30