Question: I need to build a pyramid in java this is my code so far public class EgyptianPyramid { public static void printPyramid ( char [
I need to build a pyramid in java this is my code so far public class EgyptianPyramid
public static void printPyramidchar pyramid
for int i ; i pyramid.length; i
for int j ; j pyramidilength; j
System.out.printpyramidij;
System.out.println;
public static void mainString args
Step : Read inputs
int size Integer.parseIntargs;
int bricks Integer.parseIntargs;
char pyramid new charsizebricks;
for int i ; i size; i
for int j ; j bricks; j
pyramidij;
int remainingBricks bricks;
for int row ; row size; row
int numX row ;
if numX bricks
numX bricks;
int numEquals bricks numX;
for int col numEquals; col numEquals numX; col
if remainingBricks
pyramidrowcolX; Place a brick
remainingBricks;
else
break;
printPyramidpyramid;
System.out.printlnBricksRemaining";
it gives me the output
X X X X X
X X X
X
when I test java EgyptianPyramid
the output needed is
X
XXX
XXXXX
BricksRemaining
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
