Even odd Numbers

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 20:- Even odd Numbers

In Java, you can determine whether a given number is even or odd using the modulo operator %. An even number is divisible by 2 without any remainder, while an odd number will have a remainder of 1 when divided by 2.

Here's a Java program to check whether a given number is even or odd:

javaCopy code
import java.util.Scanner; public class EvenOddChecker { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter a number: "); int number = scanner.nextInt(); // Check if the number is even or odd if (number % 2 == 0) { System.out.println(number + " is an even number."); } else { System.out.println(number + " is an odd number."); } scanner.close(); } }

Example output:

csharpCopy code
Enter a number: 25 25 is an odd number.

In the program above, we take the user input and store it in the variable number. We then use the if statement to check if the number is even or odd. If the remainder of number divided by 2 is equal to 0, it is even, and the program prints the message "is an even number." Otherwise, if the remainder is 1, it is odd, and the program prints the message "is an odd number."

Remember that 0 is considered an even number since it is divisible by 2 without a remainder. Additionally, negative numbers can also be even or odd based on the same rule.

 

Disclaimer:-

Under Section 107 of the copyright act 1976, allowance is made for fair use for purposes such as criticism, comment, news reporting, scholarship, and research. Fair use is a use permitted by copyright statute that might otherwise be infringing. Non-profit, educational, or personal use tips the balance in favor of fair use.

 

5. Flow Control

Comments: 0

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?