SEARCH

Basic java with output : The sum of all numbers in array is equals to



Basic java  with output  :   The sum of all numbers in array is equals to






import java.util.*;
public class ian
{
     static Scanner key = new Scanner (System.in);
     public static void main (String [] args)
     {
         System.out.print("Enter the size of Array : ");
         int a=key.nextInt();
         int [] var=new int [a];
         int sum = 0;
       
         for (int c=0;c<a;c++)
         {
             System.out.print("Enter "+(c+1));
             System.out.print(" number : ");
             var [c]=key.nextInt();
           
       }
         for( int num : var )
         {
          sum = sum+num;
      }
      System.out.println("The sum of all numbers is:"+sum);

   }
}





OUTPUT

Enter the size of Array :  ? (for example :  5 )
Enter 1 number :  ?  ( for example  2  ) 
Enter 2 number :  ?  ( for example  2  )
Enter 3 number :  ?  ( for example  1  )
Enter 4 number :  ?  ( for example  3  )
Enter 5 number :  ?  ( for example  5  )
The sum of all numbers is:   13









HAVE FUN CODING!



“Help us support our site by Donating a small amount of donation"

You can donate by clicking the donate button below.


No comments:

Post a Comment