Write a program to find Number is a Odd number or Even number from 1 to N.
import java.util.Scanner; public class EvenOdd { public static void main(String[] args) { int even_count=0; int odd_count=0; Scanner scan = new java.util.Scanner(System.in); System.out.println("Enter the N: "); int n=scan.nextInt(); //condition used to identify number is odd or even for(int i=1; i<=n;i++) { if(i%2==0) { even_count++; System.out.println(i + " is Even number"); } else { odd_count++; System.out.println(i + " is odd number"); } } System.out.println("Even count: "+even_count); System.out.println("Odd count: "+odd_count); } } Output: Enter the N: 10 1 is odd number 2 is Even number 3 is odd number 4 is Even number 5 is odd number 6 is Even number 7 is odd number 8 is Even number 9 is odd number 10 is Even number Even count: 5 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