Back to articles
# πŸš€ Day 25 of My Automation Journey – Deep Dive into Logic (Part 2)
How-ToTools

# πŸš€ Day 25 of My Automation Journey – Deep Dive into Logic (Part 2)

via Dev.tobala d kaveri

Continuing from earlier, here are the remaining core number programs with full step-by-step explanations to strengthen logic building πŸ‘‡ πŸ”Ή 6. Divisors of a Number – Correct Logic πŸ’» Program: int user = 15 ; for ( int i = 1 ; i <= user ; i ++) { if ( user % i == 0 ) System . out . println ( i ); } 🧠 Logic Explained: user % i == 0 means: πŸ‘‰ β€œCan i divide user without remainder?” Loop runs from 1 β†’ 15 πŸ” Step-by-Step Trace: i 15 % i Result 1 0 βœ… Print 2 1 ❌ 3 0 βœ… 4 3 ❌ 5 0 βœ… 15 0 βœ… πŸ“€ Output: 1 3 5 15 πŸ’‘ Key Insight: πŸ‘‰ Divisors are numbers that perfectly divide the given number πŸ”Ή 7. Count of Divisors πŸ’» Program: int user = 15 ; int count = 0 ; for ( int i = 1 ; i <= user ; i ++) { if ( user % i == 0 ) count ++; } System . out . println ( count ); 🧠 Logic Explained: Same logic as divisors Instead of printing β†’ we count πŸ” Example: Divisors of 15 β†’ 1, 3, 5, 15 πŸ‘‰ Count = 4 πŸ“€ Output: 4 πŸ’‘ Key Insight: πŸ‘‰ Reuse logic + add counter β†’ powerful pattern πŸ”Ή 8. Count of Digits πŸ’» Program: int user = 12345 ; int

Continue reading on Dev.to

Opens in a new tab

Read Full Article
7 views

Related Articles