🚀 Day 25 of My Automation Journey – Prime Numbers, Reverse Logic & Loops 🔁
Today, instead of just writing programs, I focused on understanding the “WHY” behind each logic. Let’s break everything down step by step 👇 🔹 1. Divisors Logic – Step-by-Step Understanding 💻 Pro...

Source: DEV Community
Today, instead of just writing programs, I focused on understanding the “WHY” behind each logic. Let’s break everything down step by step 👇 🔹 1. Divisors Logic – Step-by-Step Understanding 💻 Program: int user = 15; int i = 0; while (i <= user) { if (i % user == 0) System.out.println(i); i++; } 🧠 Logic Explained: i % user == 0 means: 👉 “Is i divisible by user?” Loop runs from 0 → 15 Let’s trace: i value i % 15 Condition 0 0 ✅ Print 1–14 Not 0 ❌ Skip 15 0 ✅ Print 📤 Output: 0 15 ⚠️ Important Insight: 👉 This program is actually finding multiples of 15 within range, NOT divisors. ✅ Correct Divisor Logic should be: if (user % i == 0) 🔹 2. Prime Number Logic – Deep Explanation 💻 Program: int user = 3; boolean status = true; int i = 2; while(i < user) { if(user % i == 0) { status = false; break; } i++; } if (status==true) System.out.println("Prime"); else System.out.println("Not a prime"); 🧠 What is a Prime Number? A number is prime if: It has exactly 2 factors → 1 and itself �