Zadanie 1 i 2 #38
BIN
zad2/Main.class
BIN
zad2/Main.class
Binary file not shown.
@ -14,7 +14,9 @@ public class Main {
|
|||||||
String multiple = Arrays.toString(PolynomialOperations.multiple(polyF, polyG, modulo));
|
String multiple = Arrays.toString(PolynomialOperations.multiple(polyF, polyG, modulo));
|
||||||
int[] divisionArray = PolynomialOperations.divide(polyF, polyG, modulo);
|
int[] divisionArray = PolynomialOperations.divide(polyF, polyG, modulo);
|
||||||
String division;
|
String division;
|
||||||
if (divisionArray.length == 0)
|
if(divisionArray == null)
|
||||||
|
division = "DivisionError";
|
||||||
|
else if (divisionArray.length == 0)
|
||||||
division = "[0]";
|
division = "[0]";
|
||||||
else
|
else
|
||||||
division = Arrays.toString(divisionArray);
|
division = Arrays.toString(divisionArray);
|
||||||
@ -22,7 +24,6 @@ public class Main {
|
|||||||
if (nwd.equals("null"))
|
if (nwd.equals("null"))
|
||||||
nwd = "DivisionError";
|
nwd = "DivisionError";
|
||||||
|
|
||||||
|
|
||||||
String outputString = "[" + multiple + ", " + division + ", " + nwd + "]";
|
String outputString = "[" + multiple + ", " + division + ", " + nwd + "]";
|
||||||
System.out.println(outputString);
|
System.out.println(outputString);
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
@ -55,7 +55,7 @@ public class PolynomialOperations {
|
|||||||
|
|
||||||
public static int[] divide(int[] n, int[] d, int mod) {
|
public static int[] divide(int[] n, int[] d, int mod) {
|
||||||
if (n.length < d.length) {
|
if (n.length < d.length) {
|
||||||
throw new IllegalArgumentException("Numerator and denominator vectors must have the same size");
|
return null;
|
||||||
}
|
}
|
||||||
int nd = n.length - 1;
|
int nd = n.length - 1;
|
||||||
int dd = d.length - 1;
|
int dd = d.length - 1;
|
||||||
@ -79,7 +79,11 @@ public class PolynomialOperations {
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
while (b.length != 0) {
|
while (b.length != 0) {
|
||||||
int[] c = divide(a, b, mod);
|
int[] c;
|
||||||
|
if (a.length >= b.length)
|
||||||
|
c = divide(a, b, mod);
|
||||||
|
else
|
||||||
|
c = divide(b, a, mod);
|
||||||
a = b;
|
a = b;
|
||||||
b = c;
|
b = c;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user