Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started