Duck Number
- Categories Java
Accept a number from user and print if given number is duck number or not.
Duck number: A Duck number is a number which has zeroes present in it. e.g 402, 280.
Watch our video on how to solve any Number Program – Click Here
import java.util.Scanner;
public class DuckNumber
{
public static void main(){
Scanner sc = new Scanner(System.in);
int n;
System.out.println("Enter any number:");
n= sc.nextInt();
int m = n;
int count = 0;
while (n != 0) {
int d = n%10;
if ( d == 0)
count++;
n = n / 10;
}
if ( count > 0)
System.out.println ("yes");
else
System.out.println ("no");
}
}
You may also like
Single Linked List Programs in Java
28 August, 2021
Implementing Stack using Array in Java
28 August, 2021
Constructor Programs
3 July, 2021