-
Notifications
You must be signed in to change notification settings - Fork 0
/
if_else.java
24 lines (23 loc) · 894 Bytes
/
if_else.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
import java.util.Scanner;
public class if_else {
public static void main(String[] args){
// Scanner scan = new Scanner(System.in);
// System.out.println("Enter your name");
// String name = scan.nextLine();
// System.out.println(name);
// The if and Else Statement
/* Counts the even and odd numbers in a list of numbers using the if...else statement. number[] is an array variable containing all the numbers and
number.length gives the number of elements in the array. */
int number[] = { 50, 65, 56, 71, 81};
int even = 0 , odd = 0;
for(int i = 0; i < number.length; i++){
if((number[i] % 2 ) == 0){
even += 1;
}
else{
odd += 1;
}
}
System.out.println("Even Numbers : " + even + " \nOdd Numbers : " + odd);
}
}