Recursion - Java -


I am working on a program where I get recursion to calculate the amount of 1/3 + 2/5 + 3 Use / 7 + 4/9 + ... + i / (2i + 1). However, I'm not sure that to show the word to my program, the user must be added to reach the number recorded. for example. If I enter 12, then I want to know how many posts of the series [1/3 + 2/5 + 3/7 + 4/9 + ... + i / (2i + 1)] are approximated Number 12 What I do not want to achieve, is the amount of input 12 which is 5.034490247342584 in this case, but I have to get the word that if I add all the numbers till that period, I will get some about 12.

Any help would be greatly appreciated!

This is my code

  import java.util.Scanner; Public class recurring {public static zero main (string [] args) {double number; Scanner input = new scanner (System.in); System.out.println ("Enter value" =); Number = input.nextInt (); System.out.println (amount (+ number) + "which should be added to reach the" + number "); } Public stable double amount (double k) {if (k == 1) 1/3 returns; And return ((k / (2 * k + 1)) + zodiac (k-1)); }}  

I do not think this problem can be resolved using recursion Should, but ... if you have to apply it to it, then this is a possible solution:

  import java.util.Scanner; Public class recurring {public static zero main (string [] args) {double number; Scanner input = new scanner (System.in); System.out.println ("Enter value" =); Number = input.nextInt (); Double result = 0; Double expected value = number; Int k = 0; While (results & lt; expected value) {k ++; Results = Yoga (K); } System.out.println (k + "is the word that should be added to reach" + + + "(" + sum (k) + ");} Public stable dual amount (double k) {if (k == 1) Returns 1/3 and return ((k / (2 * k + 1)) + Yoga (K - 1));}}  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -