Java program to find a pattern in successive nos