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

  • SEARCH
  • Home
  • 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 8431361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:50:04+00:00 2026-06-10T05:50:04+00:00

I am a new-comer to the java language, and I’m confused as to why

  • 0

I am a new-comer to the java language, and I’m confused as to why I am getting an error here.
It’s a very short piece of code that I seem to have a mental block about.
Any suggestions?

public class Rigidbody {
    public boolean checkCircleCollision(float x1,float y1,float size1,float x2,float y2,float size2){
        if(Math.sqrt(((x2-x1)^2)+((y2-y1)^2))<=(size1+size2)){
            return true;
        }
    }
}

Does anyone know what I’m missing here? (It’s probably really obvious).

  • 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-10T05:50:05+00:00Added an answer on June 10, 2026 at 5:50 am

    Well, firstly, you forgot to have an else clause:

    public boolean checkCircleCollision(float x1, float y1, float r1,
        float x2, float y2, float r2) {
      if (Math.sqrt(((x2 - x1) ^ 2) + ((y2 - y1) ^ 2)) <= (r1 + r2)){
        return true;
      } else {
        return false;
      }
    }
    

    Someone else already pointed out this can be shortened as follows:

    public boolean checkCircleCollision(float x1, float y1, float r1,
        float x2, float y2, float r2) {
      return Math.sqrt(((x2 - x1) ^ 2) + ((y2 - y1) ^ 2)) <= (r1 + r2);
    }
    

    (make sure to upvote them for pointing those out 🙂


    However, your code is still wrong.

    As stated here, Java’s ^ operator is for exclusive bitwise OR, not exponentiation. Perhaps you want Math.pow()?

    Returns the value of the first argument raised to the power of the second argument.

    public boolean checkCircleCollision(float x1, float y1, float r1,
        float x2, float y2, float r2) {
      return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)) <= (r1 + r2);
    }
    

    Or, you can also just use Math.hypot rather than rolling your own!

    Returns sqrt(x^2 + y^2) without intermediate overflow or underflow.

    public boolean checkCircleCollision(float x1, float y1, float r1,
        float x2, float y2, float r2) {
      return Math.hypot(x2 - x1, y2 - y1) <= (r1 + r2);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have come across Java code in this form for the first time: object.methodA(new
I'm new to PHP but come from a Java background and I'm trying to
I am relatively new to Visual Basic. When it comes to logging, in Java
I'm a new comer to the kinect environment, and i was trying to modify
Hello i'm a new coder to android. I have a program that Plays Pauses
im totally new when it comes to trying to make HTML code. I was
I started a new job in a company that loves using the word, enterprise.
I'm learning processing (for those who don't know its a java-based language geared towards
I have used Java, C++, .Net. (in that order). When asked about by-value vs.
Now i know that this one is actually not a very technical question but

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.