Question
import java.util.Scanner; public class Tower { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int size = scnr.nextInt(); drawTower(size); } public static
import java.util.Scanner;
public class Tower { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int size = scnr.nextInt();
drawTower(size); }
public static void drawLine(int size) { for (int i = 1; i <= size * 10 - 1; i++) { System.out.print("X"); } System.out.println(); }
public static void drawPillars(int size) { for (int i = 1; i <= size; i++) { System.out.print(" XXX"); for (int j = 1; j <= (size * 10 - 1) / 3 - 4; j++) { System.out.print(" \\"); } System.out.print(" XXX"); System.out.println(); } }
public static void drawLevel(int size) { for (int i = 1; i <= size; i++) {
System.out.print(" XXX"); for (int j = 1; j < size; j++) { System.out.print(" \\ \\ XXX"); } System.out.println(); } }
public static void drawBase(int size) { for (int i = 1; i <= size + 1; i++) { for (int j = 1; j <= size * 10 - 1; j++) { System.out.print("X"); } System.out.println(); } }
public static void drawTower(int size) { drawLine(size); drawPillars(size); for (int i = 1; i <= size; i++) { drawLine(size); drawLevel(size); } drawBase(size); } }
-----------------------------------------------------
Question:
The java program above prints a scalable tower. Based on the program, add a method to make the tower leaning. Every row leans one space more than the row above it.
Sample run:
Enter the size: 3
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXX \ \ \ \ \ XXX
XXX \ \ \ \ \ XXX
XXX \ \ \ \ \ XXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXX \ \ XXX \ \ XXX
XXX \ \ XXX \ \ XXX
XXX \ \ XXX \ \ XXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXX \ \ XXX \ \ XXX
XXX \ \ XXX \ \ XXX
XXX \ \ XXX \ \ XXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXX \ \ XXX \ \ XXX
XXX \ \ XXX \ \ XXX
XXX \ \ XXX \ \ XXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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