Write a program that produces the following output Use a cla


Write a program that produces the following output. Use a class constant to make it possible to change the number of stairs m the figure.

Solution

Please follow the code and comments for description :

CODE :

public class StairStick { // class that runs the code

public static final int steps = 5; // class constant for the number of steps

public static void main(String[] args) { // driver method
  
for (int i = 0; i < steps; i++) { // iterating over the loop for the steps
System.out.format(((steps == (i + 1)) ? \"\" : (\"%\" + ((steps - i - 1) * 5) + \"s\")) + \" o ******\" + ((i == 0) ? \"\" : (\"%\" + (i * 5) + \"s\")) + \"*\ \", \" \", \" \"); // formatting to print the head part of the man with asteriks
System.out.format(((steps == (i + 1)) ? \"\" : (\"%\" + ((steps - i - 1) * 5) + \"s\")) + \" /|\\\\ * \" + ((i == 0) ? \"\" : (\"%\" + (i * 5) + \"s\")) + \"*\ \", \" \", \" \"); // formatting the output to print the body part of the man and asteriks
System.out.format(((steps == (i + 1)) ? \"\" : (\"%\" + ((steps - i - 1) * 5) + \"s\")) + \" / \\\\ * \" + ((i == 0) ? \"\" : (\"%\" + (i * 5) + \"s\")) + \"*\ \", \" \", \" \"); // formatting the output to print the lowe body part of the man and asteriks
}
for (int j = 0; j < (steps + 1) * 5 + 2; j++) { // for the rest of the loop printing the asteriks to build a stair case
System.out.print(\"*\"); // printing the asteriks
}
System.out.println(\"\ \"); // end of the line
}
}

OUTPUT :

o *******
/|\\ * *
/ \\ * *
o ****** *
/|\\ * *
/ \\ * *
o ****** *
/|\\ * *
/ \\ * *
o ****** *
/|\\ * *
/ \\ * *
o ****** *
/|\\ * *
/ \\ * *
********************************


Hope this is helpful.

 Write a program that produces the following output. Use a class constant to make it possible to change the number of stairs m the figure. SolutionPlease follow

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site