Results 1 to 12 of 12
  1. #1
    lyzeofkiel is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Default 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. #2
    fakepics500 is offline Member
    Join Date
    Jul 2011
    Posts
    43
    Rep Power
    0

    Default

    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. #3
    lyzeofkiel is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Default

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

  4. #4
    fakepics500 is offline Member
    Join Date
    Jul 2011
    Posts
    43
    Rep Power
    0

    Default

    Quote Originally Posted by lyzeofkiel View Post
    :( 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 08:21 AM.

  5. #5
    lyzeofkiel is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Default

    thank u very much for your concern :)) nice meeting yah this forum is useful in my studies about i.T tnx a lot ^______@

  6. #6
    fakepics500 is offline Member
    Join Date
    Jul 2011
    Posts
    43
    Rep Power
    0

    Default

    nice meeting you

  7. #7
    chipp's Avatar
    chipp is offline Member
    Join Date
    Jul 2011
    Posts
    62
    Rep Power
    0

    Default

    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. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,727
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by chipp View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    chipp's Avatar
    chipp is offline Member
    Join Date
    Jul 2011
    Posts
    62
    Rep Power
    0

    Default

    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. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,727
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by chipp View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    chipp's Avatar
    chipp is offline Member
    Join Date
    Jul 2011
    Posts
    62
    Rep Power
    0

    Default

    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 12:33 PM.

  12. #12
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,727
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by chipp View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Can't figure out
    By beauti477 in forum New To Java
    Replies: 3
    Last Post: 07-20-2011, 04:58 PM
  2. Cant figure this out
    By Shimless12 in forum New To Java
    Replies: 1
    Last Post: 07-10-2011, 10:48 PM
  3. Cant figure out where went wrong.
    By leviathan in forum New To Java
    Replies: 15
    Last Post: 06-06-2010, 07:55 PM
  4. Need help - I can't figure it out.
    By Joshsmith in forum New To Java
    Replies: 2
    Last Post: 10-23-2009, 11:12 PM
  5. I can't figure this out
    By silvia in forum New To Java
    Replies: 3
    Last Post: 07-20-2007, 05:38 AM

Posting Permissions

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