# Thread: can someone please help me to figure this out >.<

1. Member
Join Date
Jul 2011
Posts
3
Rep Power
0

## can someone please help me to figure this out >.<

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 :(

2. Member
Join Date
Jul 2011
Posts
43
Rep Power
0
use code tags

i think this may be the problem
Java Code:
`lengths =(Math.sqrt(leg1*leg1) + (leg2*leg2));`
should be

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

3. Member
Join Date
Jul 2011
Posts
3
Rep Power
0
:( possible loss of precision again i use your code but error again what should i do?? :(

4. Member
Join Date
Jul 2011
Posts
43
Rep Power
0
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
Java Code:
`double lengths=0.0d`
i tried this code and it ran suceesfully
Java 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);
}
}```
[/URL]
Last edited by fakepics500; 07-24-2011 at 07:21 AM.

5. Member
Join Date
Jul 2011
Posts
3
Rep Power
0
thank u very much for your concern :)) nice meeting yah this forum is useful in my studies about i.T tnx a lot ^______@

6. Member
Join Date
Jul 2011
Posts
43
Rep Power
0
nice meeting you

7. 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

8. 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

9. 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).

10. 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

11. 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?
Last edited by chipp; 07-24-2011 at 11:33 AM.

12. 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

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•