gitweb on Svarog
projekti pod git sistemom za održavanje verzija -- projects under the git version control system
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cb88f04)
raw | patch | inline | side by side (parent: cb88f04)
author | Doni Pracner <quinnuendo@gmail.com> | |
Wed, 6 May 2015 00:09:55 +0000 (02:09 +0200) | ||
committer | Doni Pracner <quinnuendo@gmail.com> | |
Wed, 6 May 2015 00:09:55 +0000 (02:09 +0200) |
kodovi/polinomi/Paskal.java | [new file with mode: 0644] | patch | blob |
diff --git a/kodovi/polinomi/Paskal.java b/kodovi/polinomi/Paskal.java
--- /dev/null
@@ -0,0 +1,73 @@
+public class Paskal {\r
+\r
+ static final int d = 4; /* koliko mesta zauzima pojedinacni broj */\r
+\r
+ static String sep = "";\r
+\r
+ static void postaviSeparator() {\r
+ sep = "";\r
+ for (int i = 0; i < d; i++) {\r
+ sep += ' ';\r
+ }\r
+ }\r
+\r
+ static void poravnanje(int mesta) {\r
+ for (int i = 0; i < mesta; i++) {\r
+ System.out.print(sep);\r
+ }\r
+ }\r
+\r
+ static void stampajKoeficijente(PolinomL p, int mestaLevo) {\r
+ poravnanje(mestaLevo);\r
+ int maksimalniStepen = p.maksimalniStepen();\r
+ for (int stepen = 0; stepen <= maksimalniStepen; stepen++) {\r
+ Svetovid.out.print(String.format("%" + d + ".0f",\r
+ p.koeficijentUz(stepen)));\r
+ System.out.print(sep);\r
+ }\r
+ }\r
+\r
+ static void paskalovTrougao(int n) {\r
+ PolinomL poli = new PolinomL();\r
+ poli.postaviClan(1.0, 0);\r
+\r
+ PolinomL xPlus1 = new PolinomL();\r
+ xPlus1.postaviClan(1.0, 1);\r
+ xPlus1.postaviClan(1.0, 0);\r
+\r
+ stampajKoeficijente(poli, n - 1);\r
+ System.out.println();\r
+ for (int i = 2; i <= n; i++) {\r
+ poli = poli.puta(xPlus1);\r
+ stampajKoeficijente(poli, n - i);\r
+ System.out.println();\r
+ }\r
+ }\r
+\r
+ // jednostavna varijanta koja odmah stampa polinom na ekran - tacno, ali\r
+ // nije predstavljeno kako treba\r
+ static void paskalovTrougaoDirektno(int n) {\r
+ PolinomL poli = new PolinomL();\r
+ poli.postaviClan(1.0, 0);\r
+\r
+ PolinomL xPlus1 = new PolinomL();\r
+ xPlus1.postaviClan(1.0, 1);\r
+ xPlus1.postaviClan(1.0, 0);\r
+\r
+ System.out.println(poli);\r
+ for (int i = 2; i <= n; i++) {\r
+ poli = poli.puta(xPlus1);\r
+ System.out.println(poli);\r
+ }\r
+ }\r
+\r
+ public static void main(String[] args) {\r
+ System.out.println("Program stampa Paskalov trougao");\r
+ System.out.println();\r
+ System.out.println("Unesite broj do koga stampamo: ");\r
+ System.out.println();\r
+ int broj = Svetovid.in.readInt();\r
+ postaviSeparator();\r
+ paskalovTrougao(broj);\r
+ }\r
+}\r