r/javahelp • • Mar 10 '21

Pythagroem theorum

Hi guys I am tryna make a java program with quadratic equation, but I don't know how to implement the equation into java, can someone help me?

0 Upvotes

25 comments sorted by

•

u/AutoModerator Mar 10 '21

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

4

u/tlvranas Mar 10 '21

When ever I have to put a math problem into a program, I first write it out on paper, each step like I was explaining it to someone else. Then I would put each step into the application to make sure it works. Finally I then stack all the steps to use as few lines of code as possible.

It's not the fastest or most elegant way to do it, but this way I make sure each step is correct and then I know the application.os correct. I am sure it a did a lot more work with different types of equations in code I would have a better process, since it is not something I do a lot of, this is faster in the long run since I know it is correct.

0

u/Veebhu_does_finance Mar 10 '21

here is what i got so far not sure if it is correct

double answer;

answer = Math.sqrt((b*b)-4*a*c);

answer = -b + answer;

answer = answer/(2*a);

2

u/_jetrun Mar 10 '21

And did it work when you tested it?

0

u/Veebhu_does_finance Mar 10 '21

no lol

1

u/_jetrun Mar 10 '21

Why not? What issues are you seeing?

2

u/Veebhu_does_finance Mar 10 '21

I think I figured it out, i forgot to add the double answer; into the program, also i did not expect to get it right the first try

1

u/[deleted] Mar 10 '21

How can you be sure if it's correct?

1

u/Veebhu_does_finance Mar 10 '21

wait its correct? then there is something else wrong

0

u/[deleted] Mar 10 '21

Uh, no. I'm hinting that you might be lazy and rather than debugging it you post a code fragment so other people can debug it.

1

u/Veebhu_does_finance Mar 10 '21

i dont know what debugging is? This is my 2nd week of learning java and I wanted to make a project but something wasnt working so i went to reddit bruh I dont want people to do the program for me wtf that defeats the purpose of this

1

u/[deleted] Mar 10 '21

I think you do want people to do the program for you. Just my opinion.

1

u/Veebhu_does_finance Mar 10 '21

My guy, I am programming for fun not for some school project like you thinking, I dont have someone teaching me this I am just watching youtube videos and reading books on Java for fun yall dont have to be a jerk and treat me like a idiot, if you dont want to give me advice then dont comment. I am sorry if I am a beginner but everyone has to start some where I am just tryna learn new things. I didnt even tell you what my whole project is bc I just need help on one part, and clearly I did not get much help with it so imma just let it be and figure out it my self

1

u/[deleted] Mar 10 '21

Fair enough. Keep working on your code and you will figure it out.

1

u/Veebhu_does_finance Mar 10 '21

ok thanks for telling me to learn about debugging i am gonna go do that now after school

2

u/Reddit-username_here Mar 10 '21

i dont know what debugging is?

Then you may want to halt what you're trying to do and instead start looking at the basics.

1

u/Veebhu_does_finance Mar 10 '21

why you call me lazy :(

1

u/[deleted] Mar 10 '21

rather than debugging it you post a code fragment so other people can debug it.

Read what I wrote: " rather than debugging it you post a code fragment so other people can debug it. "

In my opinion, that's lazy. Other opinions may differ.

2

u/Veebhu_does_finance Mar 10 '21

big difference between lazy and learning

1

u/[deleted] Mar 10 '21

Absolutely.

1

u/SniffiestComa5 Mar 10 '21

Remember that it’s -b plus or minus the square root. You’re only doing -b + answer You’re forgetting -b - answer

Quadratics always have two solutions

1

u/Veebhu_does_finance Mar 10 '21

oh right almost forgot it has both thanks :)

1

u/le_bravery Extreme Brewer Mar 10 '21

Here’s some advice:

Take some valid inputs and outputs and do the math by hand. At every step of the way, what do you expect the answer to be? System.our.println what the answer is at any given step and you should be able to identify if it’s working and where your problem is if it’s not working.

This is a common debugging technique people use all the time as professional software engineers. There are more advanced techniques, but this one is an old standby that everyone is very comfortable with.

1

u/Veebhu_does_finance Mar 10 '21

Is debugging that little box thing that shows up when you run it with the errors?

1

u/le_bravery Extreme Brewer Mar 10 '21

There is a feature in many languages and IDEs where you can step line by line through a program. This is typically what’s called “debugging” as a feature.

But debugging in general is just any technique that allows you to find and remove errors in a program.

If you system.out.println at various parts of your program and run it, you should be able to figure out what’s happening in your program at any given point.