Q:

Java Program of Sum of Natural Numbers

0

Java Program of Sum of Natural Numbers

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.*;
import java.lang.*;
import java.io.*;

public class Natural {
    public static void main(String[] args) {
        int num = 100, sum = 0;
        for(int i = 1; i <= num; ++i)
        {
            sum += i;
        }
        System.out.println("Sum = " + sum);
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now