package l03; /** * Tests whether a number is a perfect square using double arithmetic. * algorithm. * * @author Michael Albert * */ public class TestDouble implements SquareTest{ int loops = 0; long n; public boolean isSquare(long n) { long root = (long) Math.sqrt(n); return root*root == n; } public String report() { return "A0 loops for input " + n + " was " + loops; } public static void main(String[] args) { for (long n = Integer.MAX_VALUE; n > Integer.MAX_VALUE/2; n--) { if (n % 10000000 == 0) System.out.println(n); long n2 = n * n; long root = (long) Math.sqrt(n2); if (root != n) { System.out.println("Bad" + root); return; } } } }