Write a program to find Number is a Odd number or Even number From Given Range.
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 First Number: "); int n1=scan.nextInt(); System.out.println("Enter the Second Number: "); int n2=scan.nextInt(); //condition used to identify number is odd or even System.out.println("Even no List"); for(int i=n1; i<=n2;i++) { if(i%2==0) { even_count++; System.out.println(i); } } System.out.println("Odd no List"); for(int i=n1; i<=n2;i++) { if(i%2!=0) { odd_count++; System.out.println(i); } } System.out.println("Even count: "+even_count); System.out.println("Odd count: "+odd_count); } } Output: Enter the First Number: 10 Enter the Second Number: 20 Even no List 10 12 14 16 18 20 Odd no List 11 13 15 17 19 Even count: 6 Odd count: 5
- 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