Question: Write a program to compute the following summation. sum(x)=(1+ 1 1+2 + 1 2+3 +...+ 1 n1+n if n 2 1 if n =1 n?

Write a program to compute the following summation. sum(x)=(1+ 1 1+2 + 1 2+3 +...+ 1 n1+n if n 2 1 if n =1 n? 1 The result: 1.0 n? 100 The result: 10.000000000000004

import java.util.Scanner; public class Summation { public static double sum(int n) { } public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("n? "); int n = input.nextInt(); double result = sum(n); System.out.println("The result:" + result); } } /* * Output */

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!