Pythagorean quadruples: Difference between revisions

(→‎{{header|Ruby}}: added a <lang> xxx </lang> HTML tags, also <pre> and </pre> HTML tags (the old code "swallowed up" Rust's code.)
Line 757:
 
=={{header|Java}}==
Replace translation with Java coded implementation.
{{trans|Kotlin}}
<lang java>public class PythagoreanQuadruple {
 
Compute sequence directly.
static final int MAX = 2200;
}</lang java>
static final int MAX2 = MAX * MAX * 2;
import java.util.ArrayList;
import java.util.List;
 
public class PythagoreanQuadruples {
 
public static void main(String[] args) {
static final int MAX long d = 2200;
boolean[] found = new boolean[MAX + 1]; // all false by default
System.out.printf("Values of d < %d where a, b, and c are non-zero and a^2 + b^2 + c^2 = d^2 has no solutions:%n%s%n", d, getPythagoreanQuadruples(d));
boolean[] a2b2 = new boolean[MAX2 + 1]; // ditto
int s = 3;}
 
// See: https://oeis.org/A094958
for (int a = 1; a <= MAX; a++) {
private static List<Long> getPythagoreanQuadruples(long max) {
int a2 = a * a;
List<Long> list = new ArrayList<>();
for (int b = a; b <= MAX; b++) a2b2[a2 + b * b] = true;
}long n = -1;
long m = -1;
 
forwhile (int ctrue = 1; c <= MAX; c++) {
intlong s1nTest = s(long) Math.pow(2, n+1);
slong mTest += (long) (5L * Math.pow(2, m+1));
intlong s2test = s0;
forif (int dnTest > =mTest c + 1; d <= MAX; d++) {
if (a2b2[s1]) found[d]test = truemTest;
s1 m++= s2;
s2 += 2;}
else {
test = nTest;
for (int a = 1; a <= MAX; an++) {;
}
if ( test < max ) {
list.add(test);
}
else {
int a2 = a * abreak;
}
}
return list;
 
System.out.printf("The values of d <= %d which can't be represented:\n", MAX);
for (int d = 1; d <= MAX; d++) {
if (!found[d]) System.out.printf("%d ", d);
}
System.out.println();
}
 
}</lang>
}
</lang>
 
{{out}}
<pre>
Values of d < 2200 where a, b, and c are non-zero and a^2 + b^2 + c^2 = d^2 has no solutions:
The values of d <= 2200 which can't be represented:
[1 , 2 , 4 , 5 , 8 , 10 , 16 , 20 , 32 , 40 , 64 , 80 , 128 , 160 , 256 , 320 , 512 , 640 , 1024 , 1280 , 2048 ]
</pre>