Here yo can see what is triangular number:
https://en.wikipedia.org/wiki/Triangular_number
public class NumShape { public static void main(String[] args) { class Number{ int number; public boolean isTriangular(){ int x=1; int triangularNumber=1; while(triangularNumber<number) { x++; triangularNumber=triangularNumber+x; } if(triangularNumber==number){ return true; }else { return false; } } } Number myNumber = new Number(); myNumber.number=7; System.out.println(myNumber.isTriangular()); } }