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: Can you help?

  1. #1
    Junior Member
    Join Date
    Oct 2017
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can you help?

    I have a question and I almost completed this. However, have a simple problem which I can't solve.

    Design and implement a program that uses for loops to print the following rectangular pattern with a user specified width, height and wall thickness.


    Enter width, height & thickness: 5 6 2
    *****
    *****
    ** **
    ** **
    *****
    *****

    Enter width, height & thickness: 10 10 3

    **********
    **********
    **********
    *** ***
    *** ***
    *** ***
    *** ***
    **********
    **********
    **********

    This is my code:
    int row;
    int column;
    row=0;
    column=0;
    int height;
    int width;
    int thickness;
    Scanner keyboard = new Scanner(System.in);

    System.out.print("Please enter the width: ");
    width=keyboard.nextInt();

    System.out.print("Please enter the height: ");
    height=keyboard.nextInt();

    System.out.print("Please enter the thickness: ");
    thickness=keyboard.nextInt();

    for(row = 0; row < height; row++)
    {
    for(column = 0; column < width; column++)
    {

    if(row < thickness)
    {
    System.out.print("*"); //prints top part
    }

    else if(row >= (height - thickness))
    {
    System.out.print("*"); // prints bottom part
    }

    else if( column < thickness )
    {
    System.out.print("*");

    if( column< thickness )
    {
    System.out.print("*");
    }
    }


    }

    System.out.println();
    }
    }
    }


    And I get
    **********
    **********
    **********
    ****** //
    ****** //
    ****** // In these lines I don't know how to put spaces
    ****** // between asterisks. Can you help me?
    **********
    **********
    **********

  2. #2
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    268
    My Mood
    Amused
    Thanks
    8
    Thanked 18 Times in 18 Posts

    Default Re: Can you help?

    Where is your main class ? Please post full code
    Whatever you are, be a good one