WAP to accept a number using scanner class method and check whether the number is a special number or not, if the number is special then print the message number is special otherwise number is not special.
QGP:
What do you mean by a special number?
Answers
Answered by
3
System.out,print("enter a number");
int n=sc.nextInt();
int F=1,i,c,s=0,M=n;
int d=n%10;
for(i=n;i!=0;i=i/10)
{
for(c=1;c<=d;c++)
{
F=F*c;
s=s+F;
}
if(s==M)
System.out.println("special number");
}
int n=sc.nextInt();
int F=1,i,c,s=0,M=n;
int d=n%10;
for(i=n;i!=0;i=i/10)
{
for(c=1;c<=d;c++)
{
F=F*c;
s=s+F;
}
if(s==M)
System.out.println("special number");
}
Answered by
9
import java.util.*;
public class SPECIAL_NUMBER
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int m,n,i,d,f=1,sum=0;
System.out.print("Enter a number: ");
n = sc.nextInt();
m=n;
while(m!=0)
{
d = m%10;
for(i=1;i<=d;i++)
{
f=f*i;
}
sum = sum + f;
f=1;
m=m/10;
}
if (sum==n)
{
System.out.println(n+" is a special number.");
}
else
{
System.out.println(n+" is not a special number.");
}
}
}
public class SPECIAL_NUMBER
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int m,n,i,d,f=1,sum=0;
System.out.print("Enter a number: ");
n = sc.nextInt();
m=n;
while(m!=0)
{
d = m%10;
for(i=1;i<=d;i++)
{
f=f*i;
}
sum = sum + f;
f=1;
m=m/10;
}
if (sum==n)
{
System.out.println(n+" is a special number.");
}
else
{
System.out.println(n+" is not a special number.");
}
}
}
Similar questions