Question
1. Complete the attached JAVA program to print triangles of size n by calling the three methods printTri1(int n), printTri2(int n), printTri3(int n) after modifying
1. Complete the attached JAVA program to print triangles of size n by calling the three methods printTri1(int n), printTri2(int n), printTri3(int n) after modifying the code so that they can print numbers in triangular shape as shown below(You may assume 1 n 9 for convenience.):
For n = 5 as an example, printTri1 will print:
1
6 2
10 7 3
13 11 8 4
15 14 12 9 5
printTri2 will print:
11
7 12
4 8 13
2 5 9 14
1 3 6 10 15
printTri3 will print:
5
4 13 6
3 12 19 14 7
2 11 18 23 20 15 8
1 10 17 22 25 24 21 16 9
Use System.out.printf("%3d", n) statement to print each number in 3 character places and use System.out.printf("%3s", " ") to print leading blanks.
Only for-loops must be used in these methods. (Other loop statements such as while, do while, or recursions are NOT allowed.)
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