Question: Need help in java: Write a program that prompts for an integer (that a side length) and displays, using asterisks, a filled and hollow square,

Need help in java:

Write a program that prompts for an integer (that a side length) and displays, using asterisks, a filled and hollow square, placed next to each other. For example if the side length is 5, the program should display:

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

My code is almost finished it is just not executed correctly:

public static void main(String[] args) {

// TODO Auto-generated method stub

int length;

int width;

String hollow;

String filled;

Scanner in = new Scanner(System.in);

// filled block

System.out.println("Enter length: ");

length = in.nextInt();

if (length == 0) {

length = 1;

}

System.out.println("Enter width: ");

width = in.nextInt();

if(width < 0)

{

width = 1;

}

for(int l = 0; l < length; l++)

{

for(int w = 0; w < width; w++)

{

System.out.print("*");

}

System.out.println(" ");

}

// hollow block

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!