๐ 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 ๏ฟฝ