# Java Programming | Finding even digits in number

Introduction

This is a tutorial for finding even digits in number. The program is given below that takes number from user and print even digits from it. The program is not extendable. Go enjoy the program. Lets begin……….

Program for finding even digits from number.

``````
//import Scanner as we require it.
import java.util.Scanner;

// the name of our class its public
public class EvenDigit {
//void main
public static void main (String[] args)
{
//declare int
int no,m,n;

//Declare input as scanner
Scanner input = new Scanner(System.in);

//Take input
System.out.println("Enter Number :");
no = input.nextInt();

System.out.println("Even digits are:-");
while(no>0)
{
m=no%10;
n=m%2;
if(n==0)
System.out.println(m);
no=no/10;
}
}
}
``````

Output

Enter Number :
12345
Even digits are:-
4
2

How does it work

1. You enter the number.
2. “The even digits are:- ” is printed.
3. In while loop last digit is separated and tested if even.
4. If even is true, then prints the digit.

Extending it

The program cannot be extended.

Explanation.

1. Import the Scanner.
2. Declare the class as public
3. Add the void main function
4. Add system.out.println() function with the message to enter number.
5. Declare input as Scanner.
6. Take the inputs and save it in variables.
7. Add system.out.println() function to print “Even numbers are:-“
8. Add a loop and print the digit if even.

At the end.

You learnt creating the Java program for Finding even digits in number. So now enjoy the program.

Please comment on the post and share it.
And like it if you liked.

Sharing options: