Hola, tenemos la solución a lo que buscas, has scroll y la hallarás a continuación.
Ejemplo 1: programa Java para mostrar el triángulo pascal
import java.util.Scanner;
public class PascalsTriangleJava
staticintfindFactorial(int number)int factorial;for(factorial =1; number >1; number--)
factorial *= number;return factorial;// here's the function to display pascal's trianglestaticintprintPascalTraingle(int num,int p)returnfindFactorial(num)/(findFactorial(num - p)*findFactorial(p));
public staticvoidmain(String[] args)int row, a, b;
System.out.println("Please enter number of rows: ");
Scanner sc = new Scanner(System.in);
row = sc.nextInt();
System.out.println("Here's is pascal's triangle: ");for(a =0; a < row; a++)for(b =0; b < row - a; b++)
System.out.print(" ");for(b =0; b <= a; b++)
System.out.print(" "+printPascalTraingle(a, b));
System.out.println();
sc.close();
Ejemplo 2: triángulo de pascales java
/*
Author: Jeffrey Huang
*/
import java.util.*;
public class PascalTriangleCreator
public staticlongfactorial(long n)/*
The whole purpose of this method is to find the factorial of a number,
since java does not have a built in method for it. Calculating n choose
r is done using factorial, and since this code will be used repeatedly,
it is wise to put it in a separate method.
*/long factorial;if(n==0)
factorial=1;else
factorial=1;for(int counter=1;counter<=n;counter++)
factorial=factorial*counter;return factorial;
public staticlongFinalValue(long n,long r)//Calculates n choose r by calling the factorial method.returnfactorial(n)/(factorial(n-r)*factorial(r));
public staticvoidmain(String[] args)
Scanner sc=new Scanner(System.in);long rows=1;long i,j;while(rows!=0)
sc.close();
Te mostramos las comentarios y valoraciones de los lectores
Si sostienes algún recelo y capacidad de arreglar nuestro división eres capaz de escribir una nota y con deseo lo observaremos.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)