-
Notifications
You must be signed in to change notification settings - Fork 0
/
OddEvenArray.java
48 lines (41 loc) · 1.27 KB
/
OddEvenArray.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* A program that let the user input 10 numbers and store it in an array and identify the
* numbers if it is ODD or EVEN: if it is EVEN add, else Multiply
*
* @author (artimre098)
* @version (9/25/17)
*/
import java.util.*;
public class OddEvenArray
{
public static void main(String [] args){
int x[] = new int[10];
int sum = 0;
int mul = 1;
Scanner input = new Scanner(System.in); // declare Scanner
for(int a = 0; a < x.length; a++){
System.out.print("Enter a number: ");
x[a] = input.nextInt();
if((x[a]%2) == 0){
sum += x[a];
}else{
mul *= x[a];
}
}
System.out.print('\u000C'); // use to clear the screen
System.out.print("EVEN Numbers: "); // output all even numbers
for(int b = 0; b < x.length; b ++){
if((x[b]%2) == 0){
System.out.print(x[b] + " ");
}
}
System.out.println(" = " + sum);
System.out.print("ODD Numbers: "); // output all ODD numbers
for(int b = 0; b < x.length; b ++){
if((x[b]%2) != 0){
System.out.print(x[b] + " ");
}
}
System.out.println(" = " + mul);
}
}