Cezary Baryłka
aea8d85191
Program można uruchomić za pomocą polecenia java Main "6" "[1,2,3,0,1]" "[2,4,0,0,2]"
35 lines
1.2 KiB
Java
35 lines
1.2 KiB
Java
import java.util.Arrays;
|
|
|
|
|
|
public class Main {
|
|
|
|
public static void main(String[] args) {
|
|
if (args.length == 0) {
|
|
System.out.println("Proszę podać parametry np. java Main \"6\" \"[1,2,3,0,1]\" \"[2,4,0,0,2]\"");
|
|
return;
|
|
}
|
|
int modulo = Integer.parseInt(args[0]);
|
|
int[] polyF = stringToArray(args[1]);
|
|
int[] polyG = stringToArray(args[2]);
|
|
String multiple = Arrays.toString(PolynomialOperations.multiple(polyF, polyG, modulo));
|
|
int[] divisionArray = PolynomialOperations.divide(polyF, polyG, modulo);
|
|
String division;
|
|
if (divisionArray.length == 0)
|
|
division = "[0]";
|
|
else
|
|
division = Arrays.toString(divisionArray);
|
|
String nwd = Arrays.toString(PolynomialOperations.NWD(polyF, polyG, modulo));
|
|
if (nwd.equals("null"))
|
|
nwd = "DivisionError";
|
|
|
|
|
|
String outputString = "[" + multiple + ", " + division + ", " + nwd + "]";
|
|
System.out.println(outputString);
|
|
}
|
|
|
|
private static int[] stringToArray(String str) {
|
|
return Arrays.stream(str.substring(1, str.length() - 1).split(","))
|
|
.map(String::trim).mapToInt(Integer::parseInt).toArray();
|
|
}
|
|
}
|