Question

Language- Java

It’s urgent, please help ASAP!


lE will result in a zero for the entire uhTe R will be submitted for you when time is up. D | Question 43 35 pts Write a recu
0 0
Add a comment Improve this question Transcribed image text
Answer #1


public class RecursiveSum {
  
   public static double summ = 0;
   public static int i = 0;

  
   public double sum(int n){
       ++i;  
      
   if(n>0){  
if (i%2 != 0){
   summ = summ + 1/(Math.pow(2,i-1));
}      
else{   
   summ = summ - 1/(Math.pow(2,i-1));
}
  
return sum(--n);
   }
   else{
       return summ;
   }
      
   }
  
  
   public static void main(String[] args) {
      
       int n;
      
       n = 4;
       System.out.println("n = " + n);
      
       RecursiveSum r = new RecursiveSum();
       System.out.println("sum = " + r.sum(n));

   }

}

sum 0.625

COMMENT DOWN FOR ANY QUERY RELATED TO THIS ANSWER,

IF YOU'RE SATISFIED, GIVE A THUMBS UP

Add a comment
Know the answer?
Add Answer to:
Language- Java It’s urgent, please help ASAP! lE will result in a zero for the entire...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • pls help java ASAP!!!!!!! Topic String Tokenizer Static Methods Static Variables Primitive Arrays Description Enhance the...

    pls help java ASAP!!!!!!! Topic String Tokenizer Static Methods Static Variables Primitive Arrays Description Enhance the last assignment by providing the following additional features: (The additional features are listed in bold below) Class Statistics In the class Statistics, create the following static methods (in addition to the instance methods already provided). • A public static method for computing sorted data. • A public static method for computing min value. • A public static method for computing max value. • A...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT