Create a program to calculate the sum of numbers from 0 to the number entered in Java code example
Example 1: Java program to find the sum of first 100 numbers
int sum = 0;
for(int i = 1; i <= 100; i++) {
sum = sum + i;
}
System.out.println("Sum of first 100 numbers is : " + sum);
Example 2: sum of numbers in java
public class SumNatural {
public static void main(String[] args) {
int num = 100, sum = 0;
for(int i = 1; i <= num; ++i)
{
// sum = sum + i;
sum += i;
}
System.out.println("Sum = " + sum);
}
}