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 8807199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:18:41+00:00 2026-06-14T02:18:41+00:00

After doing some intense Googling for a Diamond Problem solver in java, all I

  • 0

After doing some intense Googling for a Diamond Problem solver in java, all I could find was the OOP diamond problem. That’s not what I’m after. What I’m looking for is a simple function in java to find the solution to a diamond problem.

A diamond problem can be expressed like this:

A = C * D,

B = C + D

So, if:

A = 10, B = 7

C = 5, D = 2

What I’m attempting to do is solve a diamond problem in java quickly and effectively. I’ve tried nested for loops, but they’re extremely inefficient due to the nature of the program.

If anyone has any ideas, I would love to hear them.

Thanks!

  • 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-06-14T02:18:42+00:00Added an answer on June 14, 2026 at 2:18 am

    If we observe the following algebra:

    B^2 - 4A = (C^2 + 2CD + C^2) - 4CD = (C^2 - 2CD + D^2) = (C-D)^2

    Then we can quickly and easily make this function:

    public static double[] diamondSolve(double a, double b) {
        double temp = b * b - 4 * a;
        double difference = Math.sqrt(temp); // difference = C - D
    
        double[] retArray = new double[2];
    
        // (b + difference) / 2 = (C + D + C - D) / 2 = 2C / 2 = C
        retArray[0] = (b + difference) / 2;
    
        // B - C = C + D - C  = D
        retArray[1] = b - retArray[0];
    
        return retArray;
    }
    

    By the way, this will generate problems if 4A is bigger than B^2… in that case the answers are imaginary anyway.

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

Sidebar

Related Questions

I think it is not complicated but after doing some research I can't find
after doing some research it seems that AppDomains are not really a tool for
I've got a Java/Flex project that I'm building using Maven. After doing some research
after doing some preliminary searching, I was not able to find much information on
Update: I updated this after doing some digging and realizing that this might be
After doing some search on SO, Google and MSDN forums I've become frustrated that
I have a program that returns a comma-separated string of numbers after doing some
After doing some research, it would seem that errno 150 occurs when either table
After doing some changes to my plugin amtyThumb , I realized that there is
After doing JUnit i am doing some document based testing that has the following

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.