Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Even Or Odd Number in Java

Even Or Odd Number in Java

Sure! Here's a simple Java program to check whether a number is even or odd:


Java Program to Check Even or Odd

import java.util.Scanner;public class EvenOddCheck {    public static void main(String[] args) {        Scanner scanner = new Scanner(System.in);        System.out.print("Enter a number: ");        int number = scanner.nextInt();  // Read the number        if (number % 2 == 0) {            System.out.println(number + " is Even.");        } else {            System.out.println(number + " is Odd.");        }        scanner.close();    }}

How it Works:

  • If a number is divisible by 2 (number % 2 == 0), it is even.

  • Otherwise, it is odd.


Sample Output:

Enter a number: 77 is Odd.

or

Enter a number: 88 is Even.

Would you also like to see how to check even or odd without using if-else, like with a ternary operator? ?
It's a cool one-liner! ?

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql