OK, I have this problem, but I cannot program it correctly in Java. See the figure below, you will see a six-pointed star, each point and the intersection of lines is a letter.

The purpose is to arrange numbers from 1 to 12 so that the sum of all rows of four balls is 26, and the sum of all 6 points of the star is 26. This reduces to:
- (A + C + F + H == 26)
- (A + D + G + K == 26)
- (B + C + D + E == 26)
- (B + F + I + L == 26)
- (E + G + J + L == 26)
- (H + i + J + K == 26)
- (A + B + E + H + K + L == 26)
So, I began to program a program that will cycle through all the parameters that force the solution. The cycle works, but now it shows solutions in which one number is used more than once, which is unacceptable. How can I do this in the code so that it also checks if the variables are different or not?
if ((A!= B != C != D != E != F != G != H != I != J != K != L)
I tried above, but this does not work because it says:
incomparable types: boolean and int.
How can I do a check inside 1 or a small operator to see if all numbers are different?
(instead of creating a nested 12 * 12 instruction that checks each combination of variables)
This is my code:
public class code { public static void main(String[] args){ for(int A = 1; A < 13; A++){ for(int B = 1; B < 13; B++){ for(int C = 1; C < 13; C++){ for(int D = 1; D < 13; D++){ for(int E = 1; E < 13; E++){ for(int F = 1; F < 13; F++){ for(int G = 1; G < 13; G++){ for(int H = 1; H < 13; H++){ for(int I = 1; I < 13; I++){ for(int J = 1; J < 13; J++){ for(int K = 1; K < 13; K++){ for(int L = 1; L < 13; L++){ if ((A+C+F+H==26) && (A+D+G+K==26) && (B+C+D+E==26) && (B+F+I+L==26) && (E+G+J+L==26) && (H+I+J+K==26) && (A+B+E+H+K+L==26)){ if ((A= C != D != E != F != G != H != I != J != K != L)){ System.out.println("A: " + A); System.out.println("B: " + B); System.out.println("C: " + C); System.out.println("D: " + D); System.out.println("E: " + E); System.out.println("F: " + F); System.out.println("G: " + G); System.out.println("H: " + H); System.out.println("I: " + I); System.out.println("J: " + J); System.out.println("K: " + K); System.out.println("L: " + L); } } } } } } } } } } } } } } } }
java if-statement
Javaaaa
source share