Cube.java


Below is the syntax highlighted version of Cube.java from §5.4 Computability.


/******************************************************************************
 *  Compilation:  javac Cube.java
 *  Execution:    java Cube
 *  
 *  Searches for an integer solution to 313(a^3 + b^3) = c^3.
 *  Will this program terminate, assuming overflow never occurs?
 *
 *  % java Cube
 *
 ******************************************************************************/

public class Cube { 

    public static void main(String[] args) { 
        boolean done = false;
        for (long c = 1; !done; c++)
            for (long a = 1; a < c; a++)
                for (long b = 1; b < c; b++)
                    if (313 * (a*a*a + b*b*b) == c*c*c) done = true;
   }

}


Copyright © 2000–2017, Robert Sedgewick and Kevin Wayne.
Last updated: Fri Oct 20 14:12:12 EDT 2017.