package leetcode;

/**
 * https://leetcode.com/problems/sum-of-square-numbers/
 */
public class Problem633 {
    public boolean judgeSquareSum(int c) {
        for (int i = 1; i <= c / 2; i++) {
            double a = Math.sqrt(i);
            double b = Math.sqrt(c - i);
            if (a == (int) a && b == (int) b) {
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        Problem633 prob = new Problem633();
        System.out.println(prob.judgeSquareSum(5)); // true
        System.out.println(prob.judgeSquareSum(3)); // false
        System.out.println(prob.judgeSquareSum(Integer.MAX_VALUE)); // false
    }
}

package leetcode;

/**
 * https://leetcode.com/problems/sum-of-square-numbers/
 */
public class Problem633 {
    public boolean judgeSquareSum(int c) {
        if (c == 0) {
            return true;
        }
        for (int i = 1; i <= Math.sqrt(c); i++) {
            int a = i * i;
            if (a > c) {
                break;
            }
            double b = Math.sqrt(c - a);
            if (b == (int) b) {
                return true;
            }
        }
        return false;
    }
}

Solve problem 633