Created
March 29, 2017 23:02
-
-
Save DimasInchidi/dd740a73220957bb83cd3de9a983d059 to your computer and use it in GitHub Desktop.
Segitiga Paskal Java CLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class pascal{ | |
public static void main(String[] args) { | |
java.util.Scanner reader = new java.util.Scanner(System.in); | |
System.out.print("Enter some number: "); | |
int ns = reader.nextInt(); | |
for (int n = 0; n < ns; n++) { | |
for (int j = 0; j < (ns * 3) - (n * 7 / 2) + (ns / 3); j++) { | |
System.out.print(" "); | |
} | |
int nCk = 1; | |
for (int k = 0; k <= n; k++) { | |
int maxlebar = 6; | |
String s = Integer.toString(nCk); | |
int Panjangnye = maxlebar - s.length(); | |
int Mulainye = s.length() + Panjangnye / 2; | |
s = String.format("%" + Mulainye + "s", s); | |
s = String.format("%-" + maxlebar + "s", s); | |
System.out.print(s + " "); | |
nCk = nCk * (n - k) / (k + 1); | |
} | |
System.out.println(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment