1import java.util.Scanner;
2public class FindEvenOrOdd
3{
4 public static void main(String[] args)
5 {
6 int a;
7 Scanner sc = new Scanner(System.in);
8 System.out.println("Please enter a number to check even or odd: ");
9 a = sc.nextInt();
10 if(a % 2 == 0)
11 {
12 System.out.println("Entered number is an even number.");
13 }
14 else
15 {
16 System.out.println("Entered number is an odd number.");
17 }
18 sc.close();
19 }
20}
1// even and odd numbers in java using for loop
2import java.util.Scanner;
3public class EvenOddUsingForLoop
4{
5 public static void main(String[] args)
6 {
7 int a;
8 Scanner sc = new Scanner(System.in);
9 System.out.println("Enter number(max) to print all even and odd until: ");
10 int number = sc.nextInt();
11 System.out.println("Even numbers from 1 to " + number + " are: \n");
12 for(a = 1; a <= number; a++)
13 {
14 if(a % 2 == 0)
15 {
16 System.out.print(a + "\n");
17 }
18 }
19 System.out.println("Odd numbers from 1 to " + number + " are: \n");
20 for(a = 1; a <= number; a++)
21 {
22 if(a % 2 == 1)
23 {
24 System.out.print(a + "\n");
25 }
26 }
27 sc.close();
28 }
29}