// A number is said to be an Ugly number if and only if the number is divisible by 2, 3 and 5.
import java.util.*;
class ugly
{//class ugly opens
public static void main(String[]args)
{//main metjod opens
Scanner sc=new Scanner(System.in);
System.out.println("Enter a no");
int n=sc.nextInt();//variable n to accept the no
int c=0;//variable c to return the result in 0 or 1
while(n!=1)//21!=1 t//7!=1 t
{
if(n%2==0)//21%2==0 false//7%2==0 false
{
n=n/2;
}
else if(n%3==0)//21%3==0 t//7%3==0 false
{
n=n/3;//21/3=7
}
else if(n%5==0)//7%5==0 false
{
n=n/5;
}
else
{
System.out.println("It is not an ugly no");
c=1;
break;
}
}
if(c==0)//1==0
System.out.println("It is an ugly no");
}//main method closes
}//class closes
No comments:
Post a Comment
any problem in any program comment:-