Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Use the triangle examples left justified and right justified, and the class Triangle from the book to assist you in the following: Analyze the problem
Use the triangle examples left justified and right justified, and the class Triangle from the book to assist you in the following:
- Analyze the problem of having a class that represents triangles and prints a figure representation of the triangle to the screen.
- Design a Java solution to this problem.
- Implement a Java solution based upon your design.
class RightTriangleLeftJustifiedInMain { public static void main(String args[]) { int row, col; System.out.println(); for(row = 1; row < 6; row++) { for(col = 1; col <= row; col++) { System.out.print(row); } System.out.println(); } System.out.println(); } }
class RightTriangleRightJustifiedInMain { public static void main(String args[]) { int row, col; System.out.println(); System.out.println("Process #1 for printing the Triangle"); System.out.println(); for(row = 1; row < 6; row++) { for(col = 1; col < 6 - row; col++) { System.out.print(" "); } for(; col < 6; col++) { System.out.print(row); } System.out.println(); } System.out.println(); System.out.println("Process #2 for printing the Triangle"); System.out.println(); for(row = 1; row < 6; row++) { for(col = 1; col < 6; col++) { if(col < 6 - row) { System.out.print(" "); } else { System.out.print(row); } } System.out.println(); } System.out.println(); } }
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