- Java
- Collections Data Structure
- Stack
Triangular numbers

import java.io.IOException; publicclass Triangle { publicstaticvoid main(String[] args) throws IOException { int theNumber = 100; int theAnswer = triangle(theNumber); System.out.println("Triangle=" + theAnswer); } publicstaticint triangle(int n) { if (n == 1) return 1; elsereturn (n + triangle(n - 1)); } }
Related examples in the same category