Triangular Number Java Code True or False

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());
	}

}

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *