A number is said to be Cuckoo if the digit nine (9) is present in it. Write a JAVA program to accept a number and check whether the number is Cuckoo or not.
Answers
Answered by
4
- A number is said to be a Cuckoo of the digit 9 is present in it. Write a java program to accept a number and check whether the number is cuckoo or not.
import java.util.*;
class IfCuckoo
{
public static void main(String s[ ])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int n=sc.nextInt();
boolean x=false;
while(n!=0)
{
int d=n%10;
if(d==9)
x=true;
n/=10;
}
if(x)
System.out.println("Given number is a Cuckoo Number.");
else
System.out.println("Given number is not a Cuckoo Number.");
} // end of main method.
} // end of class.
Answered by
3
Java Program to Check weather the given no.is CUCKOO number or not.
_______________________________
A number is said to be Cuckoo if the digit nine (9) is present in it.
Example:-
1269
1629
3749
98377
7893.....etc
__________________________________
- class Cuckoo
- {
- public static void main (int n)
- {
- int m=n;
- for(int k=0;m>0;m=m/10)
- {//open of Loop brace
- k=m%10;
- if(k==9)//Condition to check whether no.is cuckoo or not
- {
- System.out.println(n+" is Cuckoo Number");
- break;
- }
- } // close of Loop brace
- if(m==0)
- System.out.println(n +" is Not a Cuckoo Number");
- }
- }
_________________________________
Input:- 23469673
Output:- 23469673 is Cuckoo Number
Similar questions