Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Database Systems

Authors: Carlo Zaniolo, Stefano Ceri, Christos Faloutsos, Richard T. Snodgrass, V.S. Subrahmanian, Roberto Zicari

1st Edition

155860443X, 978-1558604438

More Books

Students also viewed these Databases questions

Question

Prepare an electronic rsum.

Answered: 1 week ago

Question

Strengthen your personal presence.

Answered: 1 week ago

Question

Identify the steps to follow in preparing an oral presentation.

Answered: 1 week ago