Using Java please In the past you used a program to sum the

Using Java please,

In the past you used a program to sum the (integer) values between 1 and n - where n is an integer value supplied through an interactive sequence with the user. The sum of the digits can be computed directly without resorting to an iterative addition algorithm.

Like in the past prompt the user for the number & bring the number into the program via the keyboard.

Identify the mathematician who discovered the formula you used as a comment in the beginning of the source program.

Solution

import java.util.Scanner;

public class Main {

public static void main(String args[]) {

Scanner sc = new Scanner(System.in);

int n = sc.nextInt();

double sum = n*(n+1)/2; //formula to compute sum between 1 and n.

System.out.println(\"Sum: \" + sum);

sc.close();

}

}

Using Java please, In the past you used a program to sum the (integer) values between 1 and n - where n is an integer value supplied through an interactive sequ

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site