Home > Java > javaTutorial > Java simple Cattleya number code example

Java simple Cattleya number code example

Y2J
Release: 2017-04-24 11:59:12
Original
1776 people have browsed it

<span style="font-size:24px;">package 卡特兰数;
public class Catalan {
	public static void main(String[] args) {
		int n = 3;
		System.out.println(CatalanProcess(n));
	}
	private static int CatalanProcess(int n) {
		if(n <= 1){
			return 1;
		}
		int[] h = new int[n+1];
		int result = 0;
		h[0] = h[1] = 1;
		for(int i=2 ; i<=n ; i++){
			h[i] = 0;
			for(int j=0 ; j<i ; j++){
				h[i] += (h[j]*h[i-(j+1)]);
			}
		}
		result = h[n];
		return result;
	}

}</span>
Copy after login

The above is the detailed content of Java simple Cattleya number code example. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template