Yuvraj Singh Kushwah’s Post

😍 Day 17 of My Java Learning Journey – Finding Odd or Even Numbers 🔢 . Hey everyone 👋 . Today, I explored a simple but important concept 💯 ~ how to check whether numbers are odd or even in Java using conditional statements (if-else). . Here’s the code I practiced today: 👇 --------------------------------------code start-------------------------------------- public class FindOddOrEvenNumberDemo { public static void main(String[] args) { int c = 32; int d = 21; if (c % 2 == 0 && d % 2 == 0) { System.out.println("c & d both are even number"); } else if (c % 2 != 0 && d % 2 != 0) { System.out.println("c & d both are odd number"); } else if (c % 2 == 0) { System.out.println("c is even number and d is odd number"); } else { System.out.println("c is odd number and d is even number"); } } } ------------------------------------code output------------------------------------ c is even number and d is odd number ------------------------------------code end--------------------------------------- 💡 Explanation: The expression number % 2 gives the remainder when dividing the number by 2. If the remainder is 0, the number is even. If the remainder is not 0, the number is odd. . I used multiple if-else conditions to check all possibilities: Both numbers are even. Both numbers are odd. One is even and the other is odd. . 👉 In this example, c = 32 (even) and d = 21 (odd), so the output will be: ~ c is even number and d is odd number. . Building these logic-based programs helps strengthen my understanding of control flow and conditions in Java, which are essential for solving real-world coding problems. . #Java #Coding #LearnJava #100DaysOfCode #DevOps #JavaLearningJourney #Day16 #Programming #CodeWithYuvi #LogicBuilding .

  • text

To view or add a comment, sign in

Explore content categories