CODE
for (int i=0; i<inx.length; i++){
indexes[i] = Integer.parseInt(inx[i]);
}
We take all lines in the text file and stores them in a int array.
CODE
PrintStream p = new PrintStream(new FileOutputStream("C:\\output.txt"));
We open a connection to the file to allow us to write our output.
CODE
for (int i=0; i<indexes.length; i++){
int num = 0;
int pid = 0;
int rid = indexes[i];
while (pid < rid){
if (new StringBuffer(String.valueOf(num)).reverse().toString().equals(String.valueOf(num)) == true){
pid += 1;
}
num += 1;
}
We loop through all input numbers to get the corresponding palindromes. The variables:
num = The number we are looking if it is a palindrome.
pid = The index of palindrome we are at.
rid = The WANTED palindrome index.
The if line checks if the number is a palindrome. If yes, the palindrome index increments.