Question: 4. Write a method called fraction Sum that accepts an integer parameter n and returns a String containing the first n terms of the sequence:

4. Write a method called fraction Sum that accepts an integer parameter n and returns a String containing the first n terms of the sequence: o You may assume that the parameter n is > 0. o You are not doing the calculation, just creating a String containing the terms of the sequence (see format below). You must not print the sequence in the fractionSum() method, you must just build and return the String (which will be printed in the main() method). o Your method will help you practice the following concepts: 1. Cumulative concatenation algorithms 2. Fencepost algorithms o Put the method in a class named SumPrinter o Put the following main method in your program- the comments display what should be printed to the console window. public static void main(String[] args) { System.out.println(fractionsum(2)); // 1 + (1/2) System.out.println(fractionSum()); // 1 + (1/2) + (1/3) + (1/4) System.out.println(fractionSum(5)); // 1 + (1/2) + (1/3) + (1/4) + (1/5) }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
