Write a program to find Number is a Odd number or Even number using Array.
import java.util.Scanner; public class EvenOdd { public static void main(String[] args) { int even_count=0,odd_count=0; Scanner scan = new java.util.Scanner(System.in); System.out.println("Enter the Array size: "); int size=scan.nextInt(); int [] number=new int[size]; System.out.println("Enter the elements of an Array: "); for(int i=0;i<size;i++) { number[i]=scan.nextInt(); } //condition used to identify number is odd or even for(int i=0; i<size;i++) { if(number[i]%2==0) { even_count++; System.out.println(number[i] + " is Even number"); } else { odd_count++; System.out.println(number[i] + " is odd number"); } } System.out.println("Even Number Count of an array:- " + even_count); System.out.println("Odd Number Count of an array:- " + odd_count); } } Output: Enter the Array size: 6 Enter the elements of an Array: 15 96 78 35 62 45 15 is odd number 96 is Even number 78 is Even number 35 is odd number 62 is Even number 45 is odd number Even Number Count of an array:- 3 Odd Number Count of an array:- 3
- Write a program to find Number is a Odd number or Even number in simple way.
- Identify Odd or Even Number in a way is using bit-wise Operator.
- Write a program to find Number is a Odd number or Even number using Array.
- Write a program to find Number is a Odd number or Even number from 1 to N.
- Write a program to find Number is a Odd number or Even number From Given Range.
-
Write a program to find Number is a Odd or Even from 1 to N using while loop.
- Write a program to find Number is a Odd or Even from 1 to N using do-while loop.
No comments:
Post a Comment
If you have any doubts, please let me know