Java DSA Challenge Day 3 Loops and Functions

🚀 100 Days Java + DSA Challenge | Day 3 Today I worked on Loops and Functions/Methods in Java. I know these are basic problems, but solving them gave me real hands-on experience with: ✔ How loops actually work step by step ✔ How to design and call methods ✔ Breaking problems into smaller reusable parts ✔ Writing cleaner and more structured code 💻 Problems I solved today: • Print numbers (1 to N, M to N) • Reverse printing • Sum & product of ranges • Factorial • Finding factors and counting factors 📌 Here’s the code I practiced 👇 import java.util.Scanner; public class Day3 { public static void printNumbers(int n) { for(int i = 1; i <= n; i++) { System.out.print(i + " "); } System.out.println(); } public static void printNumRange(int m, int n) { for(int i = m; i <= n; i++) { System.out.print(i + " "); } System.out.println(); } public static void printReverseFromNto1(int n) { for(int i = n; i > 0; i--) { System.out.print(i + " "); } System.out.println(); } public static void printReverseFromNtoM(int m, int n) { for(int i = n; i >= m; i--) { System.out.print(i + " "); } System.out.println(); } public static void sumOfNaturalNumbersFrom1toN(int n) { int sum = 0; for(int i = 1; i <= n; i++) { sum += i; } System.out.println(sum); } public static void factorialOfNumber(int n) { int fact = 1; for(int i = 1; i <= n; i++) { fact *= i; } System.out.println(fact); } public static void sumOfMtoN(int m, int n) { int sum = 0; for(int i = m; i <= n; i++) { sum += i; } System.out.println(sum); } public static void productOfMtoN(int m, int n) { int product = 1; for(int i = m; i <= n; i++) { product *= i; } System.out.println(product); } public static void printFactorsOfNumber(int n) { for(int i = 1; i <= n; i++) { if(n % i == 0) { System.out.print(i + " "); } } } public static void countOfFactors(int n) { int count = 0; for(int i = 1; i <= n; i++) { if(n % i == 0) { count++; } } System.out.println(count); } } These may look simple, but practicing them helped me think in terms of logic, loops, and functions, which is the foundation for solving bigger DSA problems. Day by day, I’m building my problem-solving muscle 💪 #100DaysOfCode #Java #DSA #CodingJourney #Programming #SoftwareDevelopment

To view or add a comment, sign in

Explore content categories