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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started