Example of array declaration

/*Write a program that creates and initializes a four integer element array. Calculate and display the average of its values.*/


import java.util.Scanner;
class  K
   {
   public static void main(String []args)
   {
   Scanner b=new Scanner(System.in);
      int[]   arr= new int[4];
      int i;
     System.out.println("enter element");
        for(i=0; i<4; i++)
       {
           arr[i]=b.nextInt();
     }
   
   int sum=0;
  for(i=0; i<4; i++)
       {
           sum=sum+arr[i];
     }
   System.out.println("avrage of element"+ (sum/2));
}
}
       
       
   
   
   
         

Comments

Popular posts from this blog

Write a java program to calculate gross salary & net salary taking the following data

WAP a program that illustrates interface inheritance. Create two interface p1 and p2 . create Interface p which extends p1 and p2 and then create interface p12 which extends p12. Each interface declare one constants and one method. Create class Q which implements p12 and define all the methods of interface which displays value of constants

WAP that create interface on that you declare one method interest(p,r,n) then create two class simple and compound that implements interest and find simple and compound interest.