Reversing a number

i used the below code and this is running perfectly for now ,i wanted to ask if this can cause a problem somewhere
Scanner scn = new Scanner(System.in);
int num = scn.nextInt();
int rem=0;
while(num!=0){
rem=num%10;
System.out.print(rem);
num=num/10;
is it imp to use ans=ans*10+rem ?

there is no problem in using this way
and yeah u can also use ans=ans*10+rem.