Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6580087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:58:53+00:00 2026-05-25T15:58:53+00:00

I have a Java program that I must do for homework, and here’s the

  • 0

I have a Java program that I must do for homework, and here’s the formula that I must use: picture of formula. Sorry, I am not a native English speaker, and I don’t know the name of this formula.

I’ve written this solution:

/* Check: 
 * if: j<=3:
 * 
 * 1/1+sqrt2=0,414213562
 * 1/sqrt2+sqrt3=0,317837245
 * 1/sqrt3+sqrt4=0,267949192
 *      res= 0,9999999 =~1.0
 */
double sum = 0;
for (int j = 2; j <= 624; j++) 
{
    sum += 1 / ((Math.sqrt(j) + Math.sqrt(j + 1)));
}
double res = 0;
res = (double)1 / (1 + Math.sqrt(2)) + sum;

System.out.println("Result is: "  + res);

I’ve checked the program for j=2 to j=3, and it gave the right result (around 1.0). So I think it is working well. But, when I’ve tried up to j<=624, my result is: 24.000000000000014

1. How can I make the result will be 24.0 and not 24.000000000014 in my program?

2. Is there a better solution / source code for this math formula? What is this formula’s name in english?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:58:53+00:00Added an answer on May 25, 2026 at 3:58 pm

    Welcome to the world of floating-point computation. Unless you can rewrite your formula using algebra in a way that uses fewer terms or converges more rapidly, you’re out of luck — floating-point computation is never exact and accumulates errors, as you can see from your example.

    (a specific hint in this case: your terms are of the form Xk = 1 / (sqrt(k) + sqrt(k+1)). Try multiplying numerator and denominator by sqrt(k+1) – sqrt(k))

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java program that loads thirdparty class files (classes I did not
We have a java program that requires a large amount of heap space -
I have a Java program that runs many small simulations. It runs a genetic
I have a java program that will work with a variety of Java Beans.
I have a Java program that executes from Spring Qquartz every 20 seconds. Sometimes
I have a Java program that is launched by a batch file with a
I have a Java program that generates Java classes for my application. Basically it
I have a Java program that opens a file using the RandomAccessFile class. I'd
Let's say I have a java program that makes an HTTP request on a
I am wondering if such thing is possible: I have a java program that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.