java program to calculate sum of even and odd numbers in an array

Solutions on MaxInterview for java program to calculate sum of even and odd numbers in an array by the best coders in the world

showing results for - "java program to calculate sum of even and odd numbers in an array"
Milo
13 Oct 2019
1// Java program to calculate sum of even and odd numbers in an array
2import java.util.Scanner;
3public class FindSumOf
4{
5   public static void main(String[] args)
6   {
7      int number, sumEven = 0, sumOdd = 0;
8      Scanner sc = new Scanner(System.in);
9      System.out.println("Please enter number of elements in an array: ");
10      number = sc.nextInt();
11      int[] arrNumbers = new int[number];
12      System.out.println("Please enter elements of the array: ");
13      for(int a = 0; a < number; a++)
14      {
15         arrNumbers[a] = sc.nextInt();
16      }
17      for(int a = 0; a < number; a++)
18      {
19         if(arrNumbers[a] % 2 == 0)
20         {
21            sumEven = sumEven + arrNumbers[a];
22         }
23         else
24         {
25            sumOdd = sumOdd + arrNumbers[a];
26         }
27      }
28      System.out.println("Sum of even numbers in an array: " + sumEven);
29      System.out.println("Sum of odd numbers in an array : " + sumOdd);
30      sc.close();
31   }
32}
queries leading to this page
write a program to find the sum of even numbers in an array of size 10 in javalogic for find the sum odd number form n javasum of all even numbers javahow to sum all the even numbers in an array javajava program to find sum of even numbers in an arrayallintitle 3ajava program to calculate sum of even and odd numbers in an arrayfind the sum of even numbers in an array javshow to sum even numbers in javafind sum of even numbers and sum of odd numbers from 1 to 100 javahow to find the sum of odd integers javasum of odd and even digits in a number in javawrite a program to find the sum of even and odd numbers in an array in javajava program to calculate sum of even and odd numbers in an arraysum odd numbers javajava code for find the sum of n odd numberwrite a program to find the sum of odd numbers and avg of even numbers in an array in javajava program to find sum of first n odd numberssum of odd and even numbers in javaadditon of array odd numbers javaallintitle 3a java program to calculate sum of even and odd numbers in an arrayhow to find odd numbers in array in java and find sumjava program to sum of even numbershow to find odd and even numbers in array in java and fin sumsum of odd numbers in javasum of even odd numbers in javahow to sum even with odd the elements of array in javasum of odd numbers java for loopsum of all even numbers formula javafind sum of all odd numbers in a number javahow to find the sum of odd numbers in javasum of even numbers in javawap to find sum of even numbers and sum of odd numbers from 1 to 100 javasum of odd and even digits in a number program in javasum of even numbers in array javajava program for sum of even numbersjava program to calculate sum of even and odd numbers in an array