Next Number Palindrome java avg part 3

Given a number N, the program must print the next palindromic number P. 

import java.util.*;


public class Hello {

public static void main (String[] args) {

Scanner in=new Scanner(System.in);

int n=in.nextInt();

n++;

for(;;n++)

{

    int temp=n,sum=0;

    while(temp>0)

    {

        sum=(sum*10)+(temp%10);

        temp/=10;

    }

    if(n==sum)

    {

        System.out.print(n);

        break;

    }

}

}

}

Comments

Popular Posts