Skip to content

Commit

Permalink
Revert "Revert " Eveodd.java jainaman224#1467 (jainaman224#1963)" (ja…
Browse files Browse the repository at this point in the history
…inaman224#2385)" (jainaman224#2418)

This reverts commit 4889547.
  • Loading branch information
jainaman224 authored and Mrunal committed Apr 8, 2020
1 parent fbee0e2 commit d408e1f
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions 1-D_Array/Java/Eveodd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import java.util.* ;
class Eveodd
{
public static void main(String args[])
{
int o = 0,e = 0,i ,n;
Scanner sc = new Scanner(System.in);
//take input for the array size
System.out.print("Enter number of elemnts in array:");
n = sc.nextInt();
//declare array of size n
int arr[] = new int[n];
System.out.print("Enter elements:");
//take input for array elements
for(i = 0;i < n;i ++ )
{
arr[i] = sc.nextInt();
}
System.out.println("Even numbers of the array are:");
for(i = 0;i < n;i ++ )
{
//numbers divisible by 2 are even.
if((arr[i] % 2) == 0)
{
e ++ ;
System.out.println(arr[i] + " ");
}
}
System.out.println("Odd numbers of the array are:");
for(i = 0;i < n;i ++)
{
//numbers which are not divisible by 2 are odd.
if((arr[i] % 2) != 0)
{
o++ ;
System.out.println(arr[i] + " ");
}
}
System.out.println("Number of even terms in the array is:" + e + "\nAnd number of odd terms is:" +o);
}
}
//sample output:
/*Enter number of elemnts in array:6
Enter elements:1 34 0 47 134 9
Even numbers of the array are:
34
0
134
Odd numbers of the array are:
1
47
9
Number of even terms in the array is:3
And number of odd terms is:3
/

0 comments on commit d408e1f

Please sign in to comment.