forked from azure2103/program-wiz
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDuck.java
More file actions
34 lines (29 loc) · 661 Bytes
/
Duck.java
File metadata and controls
34 lines (29 loc) · 661 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Java Program to check whether a
// number is Duck Number or not.
import java.io.*;
class Duck {
// Function to check whether
// the given number is duck number or not.
static boolean check_duck(String num)
{
// Ignore leading 0s
int i = 0, n = num.length();
while (i < n && num.charAt(i) == '0')
i++;
// Check remaining digits
while (i < n) {
if (num.charAt(i) == '0')
return true;
i++;
}
return false;
}
public static void main(String args[]) throws IOException
{
String num = "1023";
if (check_duck(num))
System.out.println("It is a duck number");
else
System.out.println("It is not a duck number");
}
}