Computer Science, asked by ukp, 1 year ago

write a program in java to input a number and check whether it is a duck number or not?
example-6024
the number should have at least one zero but not at the beginning
050 is not a duck number

Answers

Answered by AidanZoldyk
1
import java.io.*;
class DuckNumber
{
InputStreamReader it = new InputStreamReader (System.in);
BufferedReader br = new BufferedReader (ir);
void input()throws IOException
{
System.out.println (Enter a number:"); // a four digit number
int check= Integer.parseInt(br.readLine());
int ch= check%10;
if ( ch ==0 )
System.out.println(" Not a duck number");
else if(ch<1000)
System.out.println("Not a duck number");
else
System.out.println("Duck Number");

}
}

THIS PROGRAM CAN BE DONE USING STREAMS
THIS PROGRAM IS APPLICABLE FOR A FOUR DIGIT NUMBER ONLY

ukp: can you do it without using buffered reader?
AidanZoldyk: parameters?
ukp: how?
AidanZoldyk: i can do that for you
ukp: please reply
AidanZoldyk: what?
ukp: please write the program without using bufferedreader
Similar questions