diff --git a/Doc/Sd1/statements.xml b/Doc/Sd1/statements.xml index 4d451b5b729fe9ef61ea20a3eacc0db26af94089..7ed6300bc55d300522e0770ff49156b1e5ae56d3 100644 --- a/Doc/Sd1/statements.xml +++ b/Doc/Sd1/statements.xml @@ -5668,28 +5668,25 @@ for (int i = 0; <emphasis role="red">!numberWasFound &&</emphasis> i < <answer> <para>We propose the following solution:</para> - <programlisting language="java">public static void main(String[] args) { - - final int highestDivisor = 20; // May be adjusted to other limits. + <programlisting language="java">final int highestDivisor = 20; // May be adjusted to other limits. - int candidate = highestDivisor; // start with highest divisor. +int candidate = highestDivisor; // start with highest divisor. - boolean atLeastOneRemainder; +boolean atLeastOneRemainder; - do { - candidate++; // next candidate value. +do { + candidate++; // next candidate value. atLeastOneRemainder = false; - for (int i = highestDivisor; 2 <= i; i--) {// Higher values are more likely having a remainder - if (0 != candidate % i) { // Is there a non-zero remainder? - atLeastOneRemainder = true; // Continue outer while, - break; // leave current for loop. - } + for (int i = highestDivisor; 2 <= i; i--) { // Higher values are more likely having a remainder + atLeastOneRemainder = 0 != candidate % i; // Continue outer while, + if (atLeastOneRemainder) { // Is there a non-zero remainder? + break; // leave current for loop. + } } - } while (atLeastOneRemainder); // Increase candidate further? +} while (atLeastOneRemainder); // Increase candidate further? - System.out.println(candidate); -}</programlisting> +System.out.println(candidate); // Print final result </programlisting> <para>Executing this code results in 232792560 for the smallest desired value.</para>