-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprgrm5.java
More file actions
44 lines (44 loc) · 1.01 KB
/
prgrm5.java
File metadata and controls
44 lines (44 loc) · 1.01 KB
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
//Accept 10 numbers from keyboard and check how many of them are even and odd. And find the grand total
import java.util.*;
public class prgrm5
{
public static void main(String args[])
{
int i;
Scanner sc=new Scanner(System.in);
int arr[]= new int[10]; //creating an array of size n
System.out.println("Enter 10 elements from the user:");
for(i=0;i<10;i++)
{
arr[i]=sc.nextInt(); //accepting elements from the user
}
System.out.println("The even numbers are:\n");
for(i=0;i<10;i++)
{
if(arr[i]%2==0)
System.out.println(arr[i]+"\t");
}
System.out.println("The odd numbers are:\n");
for(i=0;i<10;i++)
{
if(arr[i]%2!=0)
System.out.println(arr[i]+"\t");
}
System.out.println("The Sum of even numbers is:\n");
int sum=0;
for(i=0;i<10;i++)
{
if(arr[i]%2==0)
sum=sum+arr[i];
}
System.out.println(sum+ " ");
System.out.println("The Sum of odd numbers is:\n");
int sum1=0;
for(i=0;i<10;i++)
{
if(arr[i]%2!=0)
sum1=sum1+arr[i];
}
System.out.println(sum1+ " ");
}
}