Code:
import java.util.Scanner;
public class duck_number
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number to be checked");
String s = sc.next();
char c = s.charAt(0);
if(c=='0')
System.out.println(s+" is not a duck number");
else
{
int count = 0;
for(int i=1;i<s.length();i++)
{
c = s.charAt(i);
if(c=='0')
count++;
}
if(count>0)
System.out.println(s+" is a duck number");
else
System.out.println(s+" is not a duck number");
}
}
}
/*
Input : 707069
Output : It is a duck number.
Explanation: 707069 does not contains zeros at the beginning.
Input : 02364
Output : It is not a duck number.
Explanation: in 02364 there is a zero at the beginning of the number.
*/
No comments:
Post a Comment