1import java.lang.Math;
2import java.util.Scanner;
3
4public class NumberShapes {
5
6 public static void main(String[] args) {
7
8 class Number {
9
10 int number;
11
12 public boolean isTriangular() {
13
14 int x = 1;
15 int triangularNumber = 1;
16
17 while (triangularNumber < number) { // while number is greater than the triangularNumber keep going.
18 // number >
19 // trianguarNumber
20 x++;
21
22 triangularNumber = triangularNumber + x; // triangularNumber += x;
23
24 // this helps during testing to see how the counter works as we increment
25 System.out.println(triangularNumber);
26 }
27
28 // after the while loop runs we check what we have left and compare
29 if (triangularNumber == number) {
30 return true;
31 } else {
32
33 return false;
34
35 }
36
37 } // end - isTriangular()
38 } // end - Number class
39
40 Number myNumber = new Number();
41
42 myNumber.number = 21;
43
44 System.out.println(myNumber.isTriangular());
45 }
46}