Department numbers: Difference between revisions

Content deleted Content added
Edmund (talk | contribs)
Added ZX81 BASIC
Robbie (talk | contribs)
Added Java
Line 981:
 
Note that we are only showing the distinct [[combinations]] here, not all [[permutations]] of those combinations.
 
=={{header|Java}}==
{{trans|Kotlin}}
<lang Java>public class DepartmentNumbers {
public static void main(String[] args) {
System.out.println("Police Sanitation Fire");
System.out.println("------ ---------- ----");
int count = 0;
for (int i = 2; i <= 6; i += 2) {
for (int j = 1; j <= 7; ++j) {
if (j == i) continue;
for (int k = 1; k <= 7; ++k) {
if (k == i || k == j) continue;
if (i + j + k != 12) continue;
System.out.printf(" %d %d %d\n", i, j, k);
count++;
}
}
}
System.out.printf("\n%d valid combinations", count);
}
}</lang>
{{out}}
<pre>Police Sanitation Fire
------ ---------- ----
2 3 7
2 4 6
2 6 4
2 7 3
4 1 7
4 2 6
4 3 5
4 5 3
4 6 2
4 7 1
6 1 5
6 2 4
6 4 2
6 5 1</pre>
 
=={{header|Javascript}}==