1.Basic Java program to check even or add
Output:
2.Basic Java program to check even or add from 1 to 10
Output:
3.Basic Java program to check even or add from an array
Output:
Program Check even or odd without using modulus and division operators
- package com.BasicJavaProgramsExamples;
- import java.util.Scanner;
- public Class EvenOrOdd{
- public static void main(String args[]) {
- Scanner in= new Scanner(System.in);
- System.out.println("Please enter number to check even or odd");
- int n=in.nextInt();
- if(n%2==0){
- System.out.println(+n" is even number");
- } else{
- System.out.println(+n" is even number");
- }
- }
- }
Output:
- Please enter number to check even or odd
- 4
- 4 is even number
2.Basic Java program to check even or add from 1 to 10
- package com.BasicJavaProgramsExamples;
- public Class EvenOrOdd{
- public static void main(String args[]) {
- for (int a=1; a<=10; a=a++){
- if (a%2==0)
- System.out.println(a+" is even");
- else
- System.out.println(a+" is odd");
- }
- }
- }
Output:
- 1 is odd
- 2 is even
- 3 is odd
- 4 is even
- 5 is odd
- 6 is even
- 7 is odd
- 8 is even
- 9 is odd
- 10 is even
3.Basic Java program to check even or add from an array
- package com.BasicJavaProgramsExamples;
- import java.util.Scanner;
- public Class EvenOrOdd{
- public static void main(String args[]) {
- int[] numbers = new int[]{1,2,3,4,5,6,7,8,9,10};
- for (int a=0; a<=numbers .length; a=a++){
- if (numbers[i]%2==0)
- System.out.println(numbers[i]+" is even number");
- else
- System.out.println(numbers[i]+" is odd number");
- }
- }
- }
Output:
- 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
Program Check even or odd without using modulus and division operators
No comments