Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: I need help with my methods please?

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I need help with my methods please?

    import java.util.*;
    public class Triangle3{
    private static double b,h,side1,side2,side3,area;
    public static void main(String[]args){
    getSides();
    getArea();
    }

    public static void getSides(){

    Scanner in=new Scanner(System.in);

    System.out.println("Enter a side of a triangle");
    side1=in.nextDouble();
    while(side1>0){
    System.out.println("Enter another side");
    side2=in.nextDouble();
    System.out.println("Enter the last side");
    side3=in.nextDouble();

    if(side1==side2){
    if(side3==side2)
    System.out.println("Your triangle is an Equilateral Triangle");
    }

    if(side1!=side2){
    if(side3==side2)
    System.out.println("Your triangle is an Isoceles Triangle");
    }
    if(side1==side2){
    if(side3!=side2)
    System.out.println("Your triangle is an Isoceles Triangle");
    }
    if(side1!=side2){
    if(side1==side3)
    System.out.println("Your triangle is an Isoceles Triangle");
    }
    if(side1!=side2){
    if(side2!=side3)
    if(side3!=side1)
    if(side2!=side1)
    System.out.println("Your triangle is a Scalene Triangle");
    }else{
    System.out.println();
    }
    }
    }


    public static void getArea(){

    side1=b;
    side2=h;
    area=0.5*(b * h);
    System.out.println("The area of your triangle is " +area);
    }

    }

    This program is suppose to find the area of a triangle after knowing what type of triangle and getting the sides. It looks bad because I'm only a beginner lol. Can I get some help as to why I can't get the second method to work?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I need help with my methods please?

    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting.
    Its hard to read your unformatted code.
    Which method is the second one? Reading through your code makes it hard to count the methods. If you give the name of the method and what your specific problems with it that would help.

Similar Threads

  1. Help with methods
    By CSUTD in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 8th, 2011, 10:39 PM
  2. I need help with METHODS!!!
    By Slone in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 14th, 2010, 08:33 AM
  3. 1st time using methods
    By gonfreecks in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 1st, 2010, 02:37 PM
  4. methods help
    By hockey87 in forum AWT / Java Swing
    Replies: 1
    Last Post: March 9th, 2010, 11:57 PM
  5. Re-using methods?
    By Morevan in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 26th, 2010, 05:04 PM