I need to create a program that asks the user to enter the height and length (both are even numbers), and then the program will draw the house. The roof of the house (width / 2) the number of rows. An example program should look like this:
Enter height and width of the house you want me to draw (must be even numbers): 10 10
....**
.../..\
../....\
./......\
/........\
----------
|........|
|........|
|........|
|........|
|........|
|........|
|........|
|........|
|........|
|........|
----------
but this is what I keep getting only for the roof, using 10 and 10 for width and height (I haven't started the body yet):
height: 10
width: 10
....**
.../..\
.../..\
.../..\
.../..\
Does anyone know how I can place the right amount of space so that it looks like a pattern? my code is:
import java.util.Scanner;
public class QuestionCode {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int height = 0, width = 0;
String space = ".", left = "/", right = "\\";
System.out.print("height: ");
height = keyboard.nextInt();
System.out.print("width: ");
width = keyboard.nextInt();
System.out.println();
int outerSpace = ((width/2)-1);
int halfWidth = ((width/2)-2);
while (outerSpace > 0) {
System.out.print(space);
--outerSpace;
}
System.out.println("**");
while (halfWidth >= 0) {
outerSpace = ((width/2)-2);
while (outerSpace > 0) {
System.out.print(space);
--outerSpace;
}
System.out.print(left);
int innerSpace = 2;
while (innerSpace < (width-2)) {
System.out.print(space);
innerSpace *= 2;
}
System.out.println(right);
halfWidth--;
}
while (width > 0) {
System.out.print("-");
--width;
}
}
}
source
share