Anti-primes: Difference between revisions

Content deleted Content added
PureFox (talk | contribs)
Added Kotlin
PureFox (talk | contribs)
Added Java
Line 81: Line 81:


{{out}}
{{out}}
<pre>
The first 20 anti-primes are:
1 2 4 6 12 24 36 48 60 120 180 240 360 720 840 1260 1680 2520 5040 7560
</pre>

=={{header|Java}}==
{{trans|Go}}
<lang java>public class Antiprime {

static int countDivisors(int n) {
if (n < 2) return 1;
int count = 2; // 1 and n
for (int i = 2; i <= n/2; ++i) {
if (n%i == 0) ++count;
}
return count;
}

public static void main(String[] args) {
int maxDiv = 0, count = 0;
System.out.println("The first 20 anti-primes are:");
for (int n = 1; count < 20; ++n) {
int d = countDivisors(n);
if (d > maxDiv) {
System.out.printf("%d ", n);
maxDiv = d;
count++;
}
}
System.out.println();
}
}</lang>

{{output}}
<pre>
<pre>
The first 20 anti-primes are:
The first 20 anti-primes are: