Java Program:

- To print sum of 1 to N

Example:

User Input: 10

Output:
Sum of 1 to 10 : 55

import java.util.Scanner;
public class SumNumbers {
  public static void main(String []args) {
    int n;
    Scanner userInput = new Scanner(System.in);
    System.out.print("Enter last number :");
    n = userInput.nextInt();

    System.out.print("Sum of 1 to "+n+" : "+ (n*(n+1))/2);
  }
}

Output:

  Enter last number : 10
  Sum of 1 to 10 : 55
Program
number

We are using the formula of sum of natural numbers (1 to N)

(N*(N+1))/2  // N is the last number
Concept

Coming Soon !

Quick
Tutorial

Quote

We are all now connected by the Internet, like neurons in a giant brain.