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: Help with methods?

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

    Default Help with methods?

    import java.util.*;
    public class triangle{
    static double base,height,side3,area,perimeter;
    public static void main(String[]args){
    getPerimeter();
    getSides();
    }
    public static void getPerimeter(){
    Scanner in=new Scanner(System.in);
    System.out.println("Enter a side of a triangle");
    base=in.nextDouble();
    System.out.println("Enter another side");
    height=in.nextDouble();
    System.out.println("Enter the last side");
    side3=in.nextDouble();
    System.out.println("The perimeter of your triangle is " +perimeter);
    perimeter=(base+height+side3);

    }

    public static void getSides(){

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

    if(base!=height){
    if(side3==height)
    System.out.println("Your triangle is an Isoceles Triangle");
    }

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

    Can anyone help me with my code? I think there is something wrong with my first method it won't output the perimeter for me. I'm only a beginner at java so I can use some help please :]


  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: Help with methods?

    first method it won't output the perimeter for me
    Please explain what your program does when you execute it and show what is printed out.

    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

Similar Threads

  1. I need help with my methods please?
    By THeAnnonymous in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 11th, 2011, 09:22 AM
  2. Help with methods
    By CSUTD in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 8th, 2011, 10:39 PM
  3. 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
  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