- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Nth Catalan numbers in java
The nth Catalan number in terms of binomial coefficients is calculated by the formula
(n + k )/k where k varies from 2 to n and n ≥ 0. i.e.
Cn = (2n)!/((n+1)!n!)
Program
public class NthCatalanNumber { public static long fact(int i) { if(i <= 1) { return 1; } return i * fact(i - 1); } public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter a number :"); int num = sc.nextInt(); //(2n)!/(n+1)!*n! long Cn = (fact(2*num))/(fact(num+1)*fact(num)); System.out.println("Catalan number :"+Cn); } }
Output
Enter a number : 7 Catalan number :429
- Related Articles
- Catalan numbers in java
- Nth Catalan Number in Python Program
- Nth Catalan Number in Go Lang
- Python Program for nth Catalan Number
- C Program for nth Catalan Number
- C/C++ Program for nth Catalan Number?
- How to calculate catalan numbers with the method of Binominal Coefficients using Python?
- Finding nth digit of natural numbers sequence in JavaScript
- Find the Nth Ugly Number in Java
- Program to print pentatope numbers upto Nth term in C
- Finding the nth palindrome number amongst whole numbers in JavaScript
- Finding the nth digit of natural numbers JavaScript
- Java Program for nth multiple of a number in Fibonacci Series
- Random Numbers in Java
- Smith Numbers in java

Advertisements