Making numbers palindromic This is a challenge I found here. You're suppose to list how many steps it takes to convert a number to a palindromic number, where each step consists of adding number to the reverse of itself. For example, 196196871 takes 151 steps and gives me 3588816724276188853.

import java.util.ArrayList;
import java.util.Scanner;


public class Main {

    private Scanner in = new Scanner(System.in);

    public Main() {
        String input = in.nextLine();
        ArrayList&lt; Long &gt; targets = new ArrayList&lt; Long &gt;();

        // Checks if the ENTER key was pressed. ENTER is the exit key of this program.
        while(!input.equals(""))
        {
            targets.add(Long.parseLong(input));
            input = in.nextLine();
        }

        for(long target : targets)
            System.out.println(target + " gets palindromic after " + getPalSteps(target) + " steps: " + convertToPal(target));          
    }

    public long reverse(long number) {
        long reverse = 0;
        long n = number;
        while (n != 0)
        {
            reverse *= 10;
            reverse = reverse + n % 10;
            n /= 10;
        }
        return reverse;
    }

    public boolean palindrome(long number) {
        return reverse(number) == number;
    }

    public long convertToPal(long number) {
        if (number == 196)
            return -1;

        while (!palindrome(number))
        {
            number = reverse(number) + number;
        }

        return number;
    }

    public long getPalSteps(long number) {
        int steps = 0;

        if (number == 196)
            return -1;

        while (!palindrome(number))
        {
            number = reverse(number) + number;
            steps++;
        }

        if(steps &gt; 10000)
            System.out.println("Lychrel number!");

        return steps;
    }

    public static void main(String[] args) {
        new Main();
    }

}
When you add a number to its reverse, its value approximately doubles, on average.  If you do it 10000 times, you should get a result that is very roughly 210000 times the original. That will certainly overflow a long, which only holds values below 263.  You need to either


lower the iteration limit
check for overflow
use BigInteger
reinvent arithmetic for large numbers using strings or arrays




The use of OOP is awkward and inappropriate. Constructing an object should just involve just allocating and initializing some memory to model something. Your Main() constructor, though, is the entire input, calculation, and output loop of the program.

Your program isn't object-oriented at all. Just make everything static, and merge the constructor code into the main() function.