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

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!