Addition Of N Numbers in Java. Addition of Multiple Numbers in Java

 Addition Of N Numbers in Java

Addition of Multiple Numbers in Java

Addition Of N Numbers in Java. Addition of Multiple Numbers in Java


Program 1: Addition Of N Numbers in Java

 import java.util.Scanner;  
 public class addition_of_N_numbers {  
   public static void main(String[] args) {  
     Scanner sc=new Scanner(System.in);  
     double result=0;  
     System.out.println("Addtion of N Numbers");  
     System.out.println("Enter How many Numbers Addition you want to do:");  
     int N=sc.nextInt();  
     System.out.println("Enter "+N+" Numbers:");  
     int arr[]=new int[N];  
     for (int i=0;i<N;i++)//NOT TAKE <= HERE  
     {  
       arr[i]=sc.nextInt();  
     }  
     for (int i=0;i<N;i++)// NOT TAKE <= HERE  
     {  
       result=result+arr[i];  
     }  
     System.out.println("Addtion of "+N+"Numbers is: "+result);  
   }  
 }  

Program 2: Addition Of N Numbers in Java

 import java.util.Scanner;  
 public class addition_of_N_numbers_2 {  
   public static void main(String[] args) {  
   Scanner sc=new Scanner(System.in);  
   double res=0;  
   int n=0,sum=0;  
    System.out.println("Enter How Many Number Addition You Want to do");  
   int a=sc.nextInt();  
     System.out.println("Enter"+a+"Numbers:");  
    for(int i=0;i<a;i++){  
     n=sc.nextInt();  
     sum+=n;  
   }  
     System.out.println(sum);  
 }  
 }  

Post a Comment

0 Comments