Sum of Number from 1 to N

Опубликовано: 15 Август 2026
на канале: LogicLoops26
12
0

☕ Java Series – Day 21 | Sum of Numbers Using for Loop

Welcome to Day 21 of the Java Series by LogicLoops26! 🚀

In today's video, we learned how to find the sum of numbers from 1 to N using a for loop in Java.

📚 Topics Covered:

✅ Taking user input using Scanner
✅ Using a for loop
✅ Understanding initialization, condition, and increment
✅ Using an accumulator variable sum
✅ Adding numbers from 1 to N
✅ Step-by-step program explanation

💻 Example:

If the user enters 5:

1 + 2 + 3 + 4 + 5 = 15

Output:

Sum = 15

💡 Key Concept:
The sum variable stores the total value, and during each iteration, the current value of i is added to sum.

🎯 Practice Challenge:
Try writing a Java program to find the sum of all even numbers from 1 to N using a for loop.

➡️ Next Video: Another practical program using the for loop.

👍 Like | 💬 Comment | 📤 Share | 🔔 Subscribe

Follow LogicLoops26 for daily Java learning from basics to advanced.

#Java #ForLoop #CoreJava #LearnJava #JavaTutorial #JavaProgramming #Coding #JavaForBeginners #JavaInterview #LogicLoops26