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 3 of 3

Thread: what's wrong with code? Rectangle

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default what's wrong with code? Rectangle

    import java.util.Scanner;
     public class Retangle{
          Scanner input=new Scanner(System.in);
         public static void main(String args[]){ 
         double length;//The rectangle's length
         double width;//The rectangle's width
         double area;//The rectangle's area
         Scanner input=new Scanner(System.in);
         length=getLenth();// get the rectangle's from the user
         width=getWidth();//get the rectangle's from the user
         area=getArea(length,width);//get the rectangle area
         displayData(length,width,area);//display the rectangle's area
        }
         public static double getLenth(){
          double length=0.0;
          System.out.println("Please enter the length:");
          length=input.nextDouble();
          return length;
        }
         public static double getWidth(){
          double width=0.0;
          System.out.println("\nPlease enter the Width:");
          width=input.nextDouble();
          return width;
        }
        public static double getArea(double length,double width){
          return length*width;
        }
        public static void displayData(double length,double width,double area){
            System.out.println("\nThe area is:"+area);
        }
    }
    Last edited by jps; November 3rd, 2012 at 02:11 AM. Reason: added code tags


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: what's wrong with code? Rectangle

    Hi and welcome.
    Please see the announcements page for the use of code tags when posting code.

    You tell us what is wrong with the code. If you have any questions feel free to ask them.

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Location
    Windsor, Ontario
    Posts
    9
    My Mood
    Bored
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: what's wrong with code? Rectangle

    This seemed to make it work

     static Scanner input=new Scanner(System.in);

    I think it's cause it's outside the main but I'm not sure.

    Also please follow what jps has said.

Similar Threads

  1. What is wrong with my code?
    By unleashed-my-freedom in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 3rd, 2012, 12:41 AM
  2. what is wrong with my code? need help
    By balmung123 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 1st, 2012, 04:12 AM
  3. Please what is wrong with my code
    By LordDavid in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 29th, 2012, 03:33 PM
  4. What's wrong with my code?
    By mjballa in forum What's Wrong With My Code?
    Replies: 8
    Last Post: November 19th, 2011, 02:57 PM
  5. What is Wrong with my code
    By xew123 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 8th, 2011, 03:59 AM