Question: I've been working on a program that will produce a tree of figure size 6 and i seem to have a problem in my java

I've been working on a program that will produce a tree of figure size 6 and i seem to have a problem in my java code: here is my java code:

public class TreeFigure { public static void main(String[] args) { int size = 6; int numSlash = size * 4 - 2; int numDash = 0; while (size > 0) { int i = 0; while (i < size*2) { System.out.print("/"); i++; } i = 0; while (i < numDash) { System.out.print("-"); i++; } i = 0; while (i < size*2) { System.out.print("\\"); i++; } System.out.println(); size--; numDash += 2; numSlash -= 1; } } }

the output of that code is:

////////////\\\\\\\\\\\\ //////////--\\\\\\\\\\ ////////----\\\\\\\\ //////------\\\\\\ ////--------\\\\ //----------\\

However the required output should be this:

////////////\\\\\\\\\\\\ ///////////--\\\\\\\\\\\ //////////----\\\\\\\\\\ /////////------\\\\\\\\\ ////////--------\\\\\\\\ ///////----------\\\\\\\

If you can help me modify in a simple way my code, do the small changes for it to get the expected output it will be much appreciated.

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!