The best way would be find the length of the number,
public class Break
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int n= sc.nextInt();
int res,rem,num=0;
while(n!=0)
{
res = n/10;
rem = n % 10;
System.out.println(rem);
n = res;
}
}
}