Code Below:
import java.util.*;
class magic
{
public static void main()
{
Scanner s=new Scanner(System.in);
int n,x,sum,i,digit;
System.out.println("enter a no.");
n=s.nextInt();
for(x=n;x>=10;x=sum)
{
sum=0;
i=x;
while(i>0)
{
digit=i%10;
sum=sum+digit;
i=i/10;
}
}
if(x==1)
System.out.println("magic no.");
}
}