# Odd and Even

SoccerBoss
Category:
Other
Price: \$5 USD

Question description

i have this code.. but i dont know how to add all the even numbers and odd numbers enter by the user.

Example output:

There are 6 even numbers : 12, 8,28, 26, and 16

The sum of even numbers: _______

There are  and 4 odd numbers : 1, 3,15, and 11

The sum of odd numbers: _____

---------------------------------------------------------------------------------------------------------------------------------------------

import java.util.Scanner;

public class OddEven {

public static void main(String[] args) {
private static Scanner kb = new Scanner(System.in);

System.out.println("\nProgram to get 10 integers and display the odd and even numbers.\n");
System.out.println("Enter the numbers:");
int n;
int[] odd = new int[10];
int[] even = new int[10];
int oddCnt, evenCnt;
oddCnt = evenCnt = 0;
for (int k = 0; k < 10; k++) {

System.out.print((k + 1) + ") ");
n = Integer.parseInt(kb.nextLine().trim());
if (n % 2 == 0) {
even[evenCnt++] = n;
} else {
odd[oddCnt] = n;
oddCnt++;
}
}
System.out.print(
"\nThere are " + evenCnt + " even numbers: ");
int k = 0;
for (k = 0; k < evenCnt - 1; k++) {
System.out.print(even[k] + ", ");
}
System.out.println(" and " + even[k]);
System.out.print("There are " + oddCnt + " odd numbers: ");
k = 0;
for (k = 0; k < oddCnt - 1; k++) {
System.out.print(odd[k] + ", ");
}
System.out.println(" and " + odd[k]);
}
}

(Top Tutor) Daniel C.
(997)
School: Cornell University
Studypool has helped 1,244,100 students

1826 tutors are online

### Related Other questions

03/25/2015
11/30/2013
11/22/2013
11/21/2013
11/21/2013

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors