Results 1 to 4 of 4
  1. #1
    joe98 is offline Member
    Join Date
    Mar 2011
    Posts
    16
    Rep Power
    0

    Default Help with Java Question

    This is the question..
    Write a method which takes 2 integer parameters, and prints out a rectangle of *’s,
    where:
    • The 1st parameter is the width of the rectangle
    • The 2nd parameter is the height of the rectangle
    • Only the border (outer layer) of the rectangle is printed
    For example, if the method was given the values 8 and 5 (in this exact order)
    also the method should print nothing if the value of any parameters it is given is less than 2.

    Here is my code so far...

    class
    {
    public static void main(String[] args)
    {
    int a=8;
    int b=5;
    System.out.println("*");
    isArea();
    }
    public static int isArea()
    {
    int i=8;
    return i;

    }

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Your code is way off what you want, your main method should only contain a line which calls the static method.

    The static method doesn't need a return type so make it void(all it does is print everything)

    I'm guessing this is an exercise on loops so think of using them. First draw a solid rectangle and see if you can figure it out. Once you get it to draw a solid rectangle it shouldn't be too difficult for the outline.

  3. #3
    joe98 is offline Member
    Join Date
    Mar 2011
    Posts
    16
    Rep Power
    0

    Default

    Hey sundee, i have got this so far but i am stuck..


    class
    {
    public static void main(String[] args)
    {
    int a=8;
    int b=5;
    System.out.println();
    isArea();
    }
    public static int isArea()
    {
    int width=5;
    for (int i=0; i<width; i++)
    System.out.print("*");
    return 5;

    }
    }

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    There is still a lot wrong with this but your are getting close. First, this method is supposed to take two arguments. I am also not sure it should return an int. Did you try compiling it and running it? The best way to learn is to compile and run the code. Play with it, get used to common compiler errors and learn to fix them. Learn to understand exception stack traces. I also suggest you read some of the sun tutorials.

Similar Threads

  1. java question
    By joe98 in forum New To Java
    Replies: 7
    Last Post: 03-23-2011, 07:09 AM
  2. Replies: 33
    Last Post: 01-21-2011, 03:07 PM
  3. Need help with java question
    By ccie007 in forum New To Java
    Replies: 23
    Last Post: 05-18-2010, 06:32 PM
  4. Java Question :D
    By thisisIT in forum New To Java
    Replies: 6
    Last Post: 03-12-2010, 04:04 PM
  5. Java Question
    By Jay-1.1 in forum New To Java
    Replies: 11
    Last Post: 05-01-2008, 04:04 PM

Posting Permissions

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