public static void main(String[] args) {
int d1, d2, d3, d4, d5, d6, d7, d8, d9, d10; // the 10 digits from user input
int s1, s2, s3, s4; // if all = 0 then there are no errors
int s1Squared, s2Squared, s3Squared, s4Squared;
int P, Q, R; // if all = 0, then there is a single error
int qSquared; // the Product of Q * Q
int a, b; // the magnitude of the errors
int i, j; // the positions of the errors
String input; // the 10 digits input by the user
Scanner scan = new Scanner(System.in);
System.out.println("Enter a potential 10 digit codeword: ");
input = scan.nextLine();
d1 = Integer.parseInt(String.valueOf(input.charAt(0)));
d2 = Integer.parseInt(String.valueOf(input.charAt(1)));
d3 = Integer.parseInt(String.valueOf(input.charAt(2)));
d4 = Integer.parseInt(String.valueOf(input.charAt(3)));
d5 = Integer.parseInt(String.valueOf(input.charAt(4)));
d6 = Integer.parseInt(String.valueOf(input.charAt(5)));
d7 = Integer.parseInt(String.valueOf(input.charAt(6)));
d8 = Integer.parseInt(String.valueOf(input.charAt(7)));
d9 = Integer.parseInt(String.valueOf(input.charAt(8)));
d10 = Integer.parseInt(String.valueOf(input.charAt(9)));
s1 = (d1 + d2 + d3 + d4 + d5 + d6 + d7 + d8 + d9 + d10) % 11;
s2 = (d1 + 2 * d2 + 3 * d3 + 4 * d4 + 5 * d5 + 6 * d6 + 7 * d7 + 8 * d8 + 9 * d9 + 10 * d10) % 11;
s3 = (d1 + 4 * d2 + 9 * d3 + 5 * d4 + 3 * d5 + 3 * d6 + 5 * d7 + 9 * d8 + 4 * d9 + d10) % 11;
s4 = (d1 + 8 * d2 + 5 * d3 + 9 * d4 + 4 * d5 + 7 * d6 + 2 * d7 + 6 * d8 + 3 * d9 + 10 * d10) % 11;
s1Squared = (int) Math.pow(s1, 2);
s2Squared = (int) Math.pow(s2, 2);
s3Squared = (int) Math.pow(s3, 2);
s4Squared = (int) Math.pow(s4, 2);
P = (s2Squared - (s1 * s3)) % 11;
Q = ((s1 * s4) - (s2 * s3)) % 11;
R = ((s3Squared) - (s2 * s4)) % 11;
qSquared = (int) Math.pow(Q, 2);
i = (int) ((Math.sqrt(qSquared - 4 * P * R) - Q) / (2 * P)) % 11;
j = (int) (-Q - (Math.sqrt(qSquared - 4 * P * R)) / (2 * P)) % 11;
b = ((i * s1 - s2) / (i - j)) % 11;
a = s1 - b;
System.out.println(P);
System.out.println(Q);
System.out.println(R);
if (s1 == 0 && s2 == 0 && s3 == 0 && s4 == 0) {
System.out.println("There are no errors!");
}
if (P == 0 && Q == 0 && R == 0 && s1 != 0 && s2 != 0 && s3 != 0 && s4 != 0) {
System.out.println("There is 1 error");
}
}
}