• Post Reply Bookmark Topic Watch Topic
  • New Topic

My calculation doesn't go through (Java beginner equation program)  RSS feed

 
Hamed Haghjo
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is how my code is:


What I'm trying to do is make the Math.sqrt work. The program is running and all, but whatever I type the sides a,b,c to be it will give me the answer "-0.0 area units"
I tried not having this line: double area1 = s*(s-a)*(s-b)*(s-c);
and run it like: double area = Math.sqrt(s*(s-a)*(s-b)*(s-c));

But same end answer, -0.0 area units..


Help?
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is here:

Hint: what type of division is going on here?

But note: you should post real, compilable code. There is a lot of problems with the code you posted.
 
Hamed Haghjo
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



I played around with it and made it work, thanks for you reply though. If I didn't work it out by myself then I would from here.

What's wrong with my code? It works the way I wanted it to though :P
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's wrong with my code?

This line won't compile:

What is "Keyboard"? Did you write this class or import it from somewhere?

Also, your code is not proper indented to show control and structure. This may seen minor to a beginner, but it's important.
 
Hamed Haghjo
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, I can explain. Keyboard.class is a file that my teacher gave me and told me to put in the same folder as the worked .java file. It's like a scanner, but my Keyboard didn't work earlier so I used scanner and now it works so I am only going to use it to loop my code because I don't know how to do it with scanner. Which means this part: igen = Keyboard.readChar();

And oh, herons formula is actually not there. I translated my entire code to english, it says heron there otherwise.

And the way I made it look fancy, it's just an extra thing I do for myself to make it look a bit more easier and readable. I know it wont make anything with the code if I add a little spaces
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's good practice to use a Short, Self-Contained, Compilable Example. "Short" you did. Self-contained, maybe you could put a comment above Keyboard to let us know what it is. "Compilable" it wasn't. A reader should be able to cut and paste your code and run it.

I may not be understanding you correctly, but if I am, formatting your code is not just being fancy, but it's an important part of making you code understandable to others and to you if you come back to it later. It's a really good habit to start now.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!