Coding Global Background
Coding Global

if i enter a number like 031 or any number starting with zero it wont give me the correct answer.

Archived 2 years ago
4 messages
1 members
Created 2 years ago
Updated 2 years ago
Open in Discord
K
! kurapika
Verified
import java.util.Scanner;
public class NewClass40 {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println("enter a 3 digit number");
int no=sc.nextInt();
boolean isduck=false;
while(no!=0){
int digit=no%10;
if(digit==0){
isduck=true;
break;

}


no=no/10;
}


if(isduck){
System.out.println("it is duck number");

}
else{
System.out.println("it is not a duck number");
}


}
}

Replies (4)