• 07-24-2011, 06:13 AM
lyzeofkiel
import java.util.*;
public class RightTriangle{
public static void main(String[]args){
Scanner x=new Scanner(System.in);
int hyp=0;
int leg1=0;
int leg2=0;
int AngleA=0;
int lengths=0;
int perimeter=0;
int area=0;
int AngleB=0;
int sumAngles=0;
System.out.println("Enter Hypotenuse:"); //input # 5
hyp=x.nextInt();
System.out.println("Enter Leg1:"); //input #3
leg1=x.nextInt();
System.out.println("Enter Leg2:"); //input #4
leg2=x.nextInt();
System.out.println("Enter Angle A:"); //input 36
AngleA=x.nextInt();
lengths =(Math.sqrt(leg1*leg1) + (leg2*leg2)); // <--- possible loss of precision whats the error here i dont get it?? >.<
perimeter=(leg1+leg2)+hyp;
area=(leg1*leg2) / 2;
AngleB=90-AngleA;
sumAngles=(AngleA+AngleB)+90;
int AcuteA=(leg1/leg2); //then press *tan* in calc
int AcuteB=(leg2/leg1); //then press*tan* in calc

System.out.println("The Lengths of the sides of the triangle is "+lengths);
System.out.println("Perime​ter= "+perimeter);
System.out.println("Area= "+area);
System.out.println("Sum of the Angles= "+sumAngles);
System.out.println("The Measurement of Acute Angle A= "+AcuteA);
System.out.println("The Measurement of Acute Angle B= "+AcuteB);
}
}

please help me in my code what is my error if possible loss of precision is popping out there's an arrow pointing at my error see code above tnx :(
• 07-24-2011, 06:50 AM
fakepics500
use code tags

i think this may be the problem
Code:

`lengths =(Math.sqrt(leg1*leg1) + (leg2*leg2));`
should be

Code:

```double lengths lengths =Math.sqrt((leg1*leg1) + (leg2*leg2));```
or
you can use
Code:

```double lengths lengths =Math.hypot(len1,len2);```
• 07-24-2011, 07:03 AM
lyzeofkiel
:( possible loss of precision again i use your code but error again what should i do?? :(
• 07-24-2011, 07:18 AM
fakepics500
Quote:

Originally Posted by lyzeofkiel
:( possible loss of precision again i use your code but error again what should i do?? :(

did you forget to convert your lengths to double type
Code:

`double lengths=0.0d`
i tried this code and it ran suceesfully
Code:

```import java.util.*; public class r{ public static void main(String[]args){ Scanner x=new Scanner(System.in); int hyp=0; int leg1=0; int leg2=0; int AngleA=0; double lengths=0.0d;//change to double int perimeter=0; int area=0; int AngleB=0; int sumAngles=0; System.out.println("Enter Hypotenuse:"); hyp=x.nextInt(); System.out.println("Enter Leg1:"); leg1=x.nextInt(); System.out.println("Enter Leg2:"); leg2=x.nextInt(); System.out.println("Enter Angle A:"); AngleA=x.nextInt(); lengths =Math.sqrt((leg1*leg1) + (leg2*leg2)); perimeter=(leg1+leg2)+hyp; area=(leg1*leg2) / 2; AngleB=90-AngleA; sumAngles=(AngleA+AngleB)+90; int AcuteA=(leg1/leg2); // int AcuteB=(leg2/leg1); // System.out.println("The Lengths of the sides of the triangle is "+lengths); System.out.println("Perime​ter= "+perimeter); System.out.println("Area= "+area); System.out.println("Sum of the Angles= "+sumAngles); System.out.println("The Measurement of Acute Angle A= "+AcuteA); System.out.println("The Measurement of Acute Angle B= "+AcuteB); } }```
http://img228.imageshack.us/img228/5185/unledyl.jpg[/URL]
• 07-24-2011, 07:39 AM
lyzeofkiel
thank u very much for your concern :)) nice meeting yah this forum is useful in my studies about i.T tnx a lot ^______@ :D:
• 07-24-2011, 07:43 AM
fakepics500
nice meeting you :(handshake): :(party):
• 07-24-2011, 07:50 AM
chipp
i have a little problem with eclipse. i don't know how to compile it, how to change to another project (it always open the last project). i tried to "run" it. but it always directing you to "run as..." and there's 2 options in there something called "ant build" (don't have idea). does anybody know the solution? btw, my eclipse is:

Eclipse IDE for Java Developers 1.2.2.20100216-1730 epp.package.java
• 07-24-2011, 07:55 AM
JosAH
Quote:

Originally Posted by chipp
i have a little problem with eclipse. i don't know how to compile it, how to change to another project (it always open the last project). i tried to "run" it. but it always directing you to "run as..." and there's 2 options in there something called "ant build" (don't have idea). does anybody know the solution? btw, my eclipse is:

Eclipse IDE for Java Developers 1.2.2.20100216-1730 epp.package.java

Have you selected File > New > Project ... and created one? Next, after adding Java files to your project (and fixing all compilation errors) you can run it by defining a 'run configuration': go to Run > Run Configuration ... and define one, i.e. define a Java Application, name it and set the class name that contains your main method. You can define several run configurations for your convenience (one or more per project for all your projects).

kind regards,

Jos
• 07-24-2011, 08:49 AM
chipp
i actually write it down in notepad, i plan ± to compile it like compiling c++ code (much easier) that's why i don't use "new project". but the tools in there is very strange (unfamiliar).
• 07-24-2011, 09:40 AM
JosAH
Quote:

Originally Posted by chipp
i actually write it down in notepad, i plan ± to compile it like compiling c++ code (much easier) that's why i don't use "new project". but the tools in there is very strange (unfamiliar).

Very strange doesn't mean not handy; either use Eclipse or don't use it. Eclipse can't know that you've created and edited a file with some external editor; especially not if you've done that outside of its workspace and without defining a project. It seems that you're better off by not using Eclipse at all.

kind regards,

Jos
• 07-24-2011, 11:30 AM
chipp
oic, so i better use javac for short? (but actually, jdk not installed yet in my system) or maybe i should copy that file to eclipse's new project :D (but this is really strange, i just got this kinda IDE) btw, which is better: eclipse or netbeans? and what's ant build actually?
• 07-24-2011, 11:34 AM
JosAH
Quote:

Originally Posted by chipp
oic, so i better use javac for short? (but actually, jdk not installed yet in my system) or maybe i should copy that file to eclipse's new project :D

It's up to you but if I were you I'd start with the basics and used the JDK with its command line tools so nothing will happen behind your back; Eclipse can do so much for you and if you don't know what you're doing (yet) the most mysterious things (to you, that is) can happen.

kind regards,

Jos