DEV Community

Discussion on: Square a number: awful answers only

Collapse
 
berolomsa profile image
berolomsa • Edited

Beg for mercy.

    private static int square(int value) {
        Random random = new Random();
        while (true) {
            int squared = random.nextInt(Integer.MAX_VALUE);
            if (squared % value == 0 && squared / value == value) {
                return squared;
            }
        }
    }
Enter fullscreen mode Exit fullscreen mode