forked from jainaman224/Algo_Ds_Notes
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…inaman224#2385)" (jainaman224#2418) This reverts commit 4889547.
- Loading branch information
1 parent
fbee0e2
commit d408e1f
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
/ |