Java 5 Extra practice and review not about naming and scope

Java:

5. Extra practice and review (not about naming and scope): Write a class TriangleTable. A TriangleTable is defined by an integer n > 0. There are n rows in the table. Row i (starting from 0) contains the numbers from i down to 0. For example, a TriangleTable of size 4 would look like the following: 1 0 2 1 0 3 2 1 0 Your class should have a method that prints the instance nicely (like above). Your program should create and print tables of size from 1 to 10.

Solution

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chegg;

public class TriangleTable {
private int n;
  
public TriangleTable(int n)
{
this.n = n;
}
  
public void printTable()
{
int i=1;
for(i=1;i<=n;i++)
{
int j = i;
  
while(j>=0)
{
System.out.print(j + \" \");
j--;
}
}
System.out.println();
}

public static void main(String[] args)
{
int i=1;
TriangleTable t;
  
for(i=1;i<=10;i++)
{
t = new TriangleTable(i);
t.printTable();
}
}
  
}

Java: 5. Extra practice and review (not about naming and scope): Write a class TriangleTable. A TriangleTable is defined by an integer n > 0. There are n row

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site