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

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!