Program to Check If a Number is Magic number or not
Steps--
Program :-
class Magic
{
public static void main(String[] args)
{
System.out.println("Enter the value");
int n1=new java.util.Scanner(System.in).nextInt();
int num, rem=1, sum=0;
num=n1;
while (num>9)
{
while(num>0)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}
num=sum;
sum=0;
}
if (num==1)
{
System.out.println(n1 + " is a Magic number ");
}
else
{
System.out.println(n1 + " is a not Magic number");
}
}
}
For Proper Understanding Watch the Video :-
Thanks;)
All the Best :)
Keep Learning:)
Study:)
No comments:
Post a Comment