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: d5f641d)
raw | patch | inline | side by side (parent: d5f641d)
author | Doni Pracner <quinnuendo@gmail.com> | |
Wed, 6 May 2015 00:09:37 +0000 (02:09 +0200) | ||
committer | Doni Pracner <quinnuendo@gmail.com> | |
Wed, 6 May 2015 00:09:37 +0000 (02:09 +0200) |
kodovi/polinomi/PolSuma.java | patch | blob | history | |
kodovi/polinomi/PolinomDemo.java | patch | blob | history |
index 021ec131f17b5714b41e816d4317ea2b2154eaea..1794c4ea466a8fd5e431a9aef933909c0a66fb37 100644 (file)
\r
int k;\r
\r
- do {\r
- System.out.print("Unesite broj k ( >0 ) ");\r
- k = Svetovid.in.readInt();\r
- } while (1 > k);\r
+ System.out.print("Unesite broj k ( >0 ) ");\r
+ k = Svetovid.in.readInt();\r
\r
- PolinomL[] p = new PolinomL[k];\r
+ if (k > 0) {\r
\r
- for (int i = 0; i < k; i++) {\r
- System.out.println();\r
- System.out.print("Unos ");\r
- System.out.print(i + 1);\r
- System.out.print(". polinoma.");\r
- System.out.println();\r
- p[i] = new PolinomL();\r
- p[i].unos();\r
- }\r
+ PolinomL[] p = new PolinomL[k];\r
\r
- for (int i = 1; i <= k; i++) {\r
- System.out.println((i + 1) + ". polinom: "+p[i]);\r
- }\r
+ for (int i = 0; i < k; i++) {\r
+ System.out.println();\r
+ System.out.print("Unos polinoma broj ");\r
+ System.out.print(i + 1);\r
+ System.out.println();\r
+ p[i] = new PolinomL();\r
+ p[i].unos();\r
+ }\r
\r
- PolinomL suma = new PolinomL();\r
- for (int i = 1; i <= k; i++) {\r
- suma.saberiNa(p[i]);\r
- }\r
+ for (int i = 0; i < k; i++) {\r
+ System.out.println("polinom broj " + (i + 1) + ": " + p[i]);\r
+ }\r
\r
- System.out.println();\r
- System.out.println("Njihova suma je: " + suma);\r
+ PolinomL suma = new PolinomL();\r
+ for (int i = 0; i < k; i++) {\r
+ suma.saberiNa(p[i]);\r
+ }\r
+\r
+ System.out.println();\r
+ System.out.println("Njihova suma je: " + suma);\r
+\r
+ } else { //k <= 0\r
+ System.out.println("Pogresna vrednost za k, nije moguce nastaviti");\r
+ }\r
}\r
\r
}\r
index d4c7fee8d4e1d65320686b4762ffd7441ecd951a..cc158f158c3fdb2f9569f4afe3887d97c0f440c5 100644 (file)
-\r
+/**\r
+ * Zadatak: formirati polinom 'p' od korisničkog unosa. Formirati polinom 'q'\r
+ * tako da bude jednak sa x^5 - 3x^4 + 4.5x + 7. Izračunati zbir ova dva\r
+ * polinoma.\r
+ *\r
+ */\r
public class PolinomDemo {\r
- \r
- public static void main(String[] args){\r
- \r
- PolinomL p, q, rez;\r
- \r
- /*Korisnik unosi prvi polinom*/\r
- p = new PolinomL();\r
+\r
+ public static void main(String[] args) {\r
+\r
+ /* Korisnik unosi prvi polinom */\r
+ PolinomL p = new PolinomL();\r
System.out.println("Unestite polinom: ");\r
p.unos();\r
- \r
- /*Drugi polinom kreiramo mi, monom po monom*/\r
- q = new PolinomL();\r
- /*Postavimo clan x^5*/\r
+\r
+ /* Drugi polinom kreiramo mi, monom po monom */\r
+ PolinomL q = new PolinomL();\r
+ /* Postavimo clan x^5 */\r
q.postaviClan(1.0, 5);\r
/*-3 x^4*/\r
q.postaviClan(-3.0, 4);\r
- /*4 x*/\r
- q.postaviClan(4.0, 1);\r
- /*7 x^0*/\r
+ /* 4 x */\r
+ q.postaviClan(4.5, 1);\r
+ /* 7 x^0 */\r
q.postaviClan(7.0, 0);\r
- \r
- /*Sabiramo polinome*/\r
- rez = p.saberi(q);\r
- \r
- /*Odstampamo rezultat i polinome*/\r
+\r
+ /* Sabiramo polinome */\r
+ PolinomL rez = p.saberi(q);\r
+\r
+ /* Odstampamo rezultat i polinome */\r
System.out.println("p: " + p);\r
System.out.println();\r
System.out.println("q: " + q);\r
System.out.println();\r
System.out.println("rez: " + rez);\r
System.out.println();\r
- \r
+\r
}\r
\r
}\r