Results 1 to 4 of 4
  1. #1
    Patricia6946 is offline Member
    Join Date
    Jan 2013
    Rep Power

    Default Whats missing in this code?

    Hi all,

    Im new to JAVA and i seem to have figured out to make the correct code for calculating the area of a rectangle.
    However something goes terribly wrong when i want to continue and code to calculate for the perimeter as well.
    Im just totally stuck and dont know how to proceed. Ive tried a lot of things but just get errors. Please help.

    This is my code so far.

    import java.util.Scanner;

    public class TriangleArea {
    public static void main(String [] args)
    Scanner sc = new Scanner(;
    double base = 0;
    double height = 0;
    System.out.print("Enter the base: ");
    base = sc.nextInt();
    System.out.print("Enter the height");
    height = sc.nextInt();
    double area = base * height;
    System.out.print("Area of rectangle is : "+ area);

    --------------------------------------------------------------------> (until here everything is fine... now the next line is getting me into trouble when i want to calculate the perimeter. How shall i proceed? Please no rude comments. Im trying my hardest to learn and Im very new to this and need all the help i can get.

    System.out.print ("Enter the base and height") ;

    double perimeter = 2 * (base + height);

    System.out.print("Perimeter of square is: " + perimeter)

    Kind regards

  2. #2
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Rep Power

    Default Re: Whats missing in this code?

    Hi Patricia,

    Can you please explain what errors you are getting.

    I've not looked hard at the code and just ran it to see what it does and have noticed two issues.
    Firstly, you missed the semicolon off your last print statement. Secondly, the scanner is attempting to read in an int when you are assigning it to a double. I suspect you mean for this to be a decimal value so you will need to change the method called.


  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: Whats missing in this code?

    Patricia6946, please go through the Forum Rules, particularly the third paragraph. Also go through and BB Code List - Java Programming Forum - Learn Java Programming and edit your post accordingly.

    To change the subject line, click 'Edit Post' and then 'Go Advanced'

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default Re: Whats missing in this code?

    How strange; the class is named TriangleArea but it tries to compute the area of a rectangle ...

    kind regards,

    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Whats wrong with my jsp code?
    By ur2cdanger in forum JavaServer Pages (JSP) and JSTL
    Replies: 5
    Last Post: 10-28-2011, 04:16 AM
  2. whats wrong with my code
    By naved in forum New To Java
    Replies: 5
    Last Post: 07-15-2011, 02:06 AM
  3. Whats wrong with my code
    By zit1343 in forum New To Java
    Replies: 9
    Last Post: 01-24-2011, 01:06 AM
  4. whats wrong with my code?
    By beandip408 in forum New To Java
    Replies: 6
    Last Post: 11-03-2010, 12:01 AM
  5. Whats with my code??
    By RSYR in forum New To Java
    Replies: 6
    Last Post: 11-05-2009, 12:04 AM

Tags for this Thread

Posting Permissions

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