Write Java Source code: How to Add Numbers inside an Array using For Loop
Sample Output:
Enter the size of the input you want to enter: 5
Enter 5 numbers: 2 5 3 7 25
The sum of the numbers is:42
Source Code:
//java class
public
class
ArraySum
{
public
int
sumOfArray(int[] array)
{
int
sum = 0;
for(int
i=0; i<array.length; i++)
{
sum
= sum + array[i];
}
return
sum;
}
}
//main class
import
java.util.Scanner;
public
class
Main
{
public
static
void
main(String[]
args)
{
Scanner
input = new
Scanner(System.in);
System.out.print("Enter
the size of the input you want to enter: ");
int
size = input.nextInt();
int[]
numArr = new
int[size];
System.out.print("Enter
"+ size +" numbers: ");
for(int
i=0; i<numArr.length; i++)
{
numArr[i]=input.nextInt();
}
ArraySum
access = new
ArraySum();
System.out.print("The
sum of the numbers is:"
+
access.sumOfArray(numArr));
}
}
Mohammad Ashraful Hasan Sobuj
ReplyDeleteMy Batch- 46th
My Department :CSE
My ID 201420656
public class ArraySum
{
public int sum OfArray(int[] a)
{
int sum = 0;
for(int i=0; i<a.length; i++)
{
sum = sum + a[i];
}
return sum;
}
}
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the size of the input you want to enter: ");
int size = input.nextInt();
int[] numA = new int[size];
System.out.print("Enter "+ size +" numbers: ");
for(int i=0; i<numA.length; i++)
{
numA[i]=input.nextInt();
}
ArraySum access = new ArraySum();
System.out.print("The sum of the numbers is:" + access.sum OfArray(numA));
}
}
ID-201420406
ReplyDeleteBatch-46th
//java class
public class ArraySum
{
public int sumOfArray(int[] array)
{
int sum = 0;
for(int i=0; i<array.length; i++)
{
sum = sum + array[i];
}
return sum;
}
}
//main class
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the size of the input you want to enter: ");
int size = input.nextInt();
int[] numArr = new int[size];
System.out.print("Enter "+ size +" numbers: ");
for(int i=0; i<numArr.length; i++)
{
numArr[i]=input.nextInt();
}
ArraySum access = new Array Sum();
System.out.print("The sum of the numbers is:" + access.sumOfArray(numArr));
}
}
sultana razia khan
ReplyDeleteMy Batch- 46th
My Department :CSE
My ID 201420715
public class ArraySum
{
public int sum OfArray(int[] arr)
{
int sum = 0;
for(int i=0; i<arr.length; i++)
{
sum = sum + arr[i];
}
return sum;
}
}
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the size of the input you want to enter: ");
int size = input.nextInt();
int[] numArr = new int[size];
System.out.print("Enter "+ size +" numbers: ");
for(int i=0; i<numArr.length; i++)
{
numArr[i]=input.nextInt();
}
ArraySum access = new ArraySum();
System.out.print("The sum of the numbers is:" + access.sum OfArray(numArr));
}
}
Sharmin Akter
ReplyDeleteMy Batch- 46th
My Department :CSE
My ID 201420769
public class ArraySum
{
public int sum OfArray(int[] a)
{
int sum = 0;
for(int i=0; i<a.length; i++)
{
sum = sum + a[i];
}
return sum;
}
}
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the size of the input you want to enter: ");
int size = input.nextInt();
int[] numA = new int[size];
System.out.print("Enter "+ size +" numbers: ");
for(int i=0; i<numA.length; i++)
{
numA[i]=input.nextInt();
}
ArraySum access = new ArraySum();
System.out.print("The sum of the numbers is:" + access.sum OfArray(numA));
}
}
This comment has been removed by the author.
ReplyDeleteName: Rashed Prodhania (Jewel)
ReplyDeleteID:201420763
Batch: 46th
public class ArraySum
{
public int sumOfArray(int[] array)
{
int sum = 0;
for(int i=0; i<array.length; i++)
{
sum = sum + array[i];
}
return sum;
}
}
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the size of the input you want to enter: ");
int size = input.nextInt();
int[] numArr = new int[size];
System.out.print("Enter "+ size +" numbers: ");
for(int i=0; i<numArr.length; i++)
{
numArr[i]=input.nextInt();
}
ArraySum access = new Array Sum();
System.out.print("The sum of the numbers is:" + access.sumOfArray(numArr));
}
}
Name : Jalis mahmud
ReplyDeleteID : 201420762
Batch : 46
public class ArraySum
{
public int sum OfArray(int[] x)
{
int sum = 0;
for(int i=0; i<x.length; i++)
{
sum = sum + x[i];
}
return sum;
}
}
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the size of the input you want to enter: ");
int size = input.nextInt();
int[] numA = new int[size];
System.out.print("Enter "+ size +" numbers: ");
for(int i=0; i<numA.length; i++)
{
numA[i]=input.nextInt();
}
ArraySum access = new ArraySum();
System.out.print("The sum of the numbers is:" + access.sum OfArray(numA));
}
}