Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class EvenDigits {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int inputNum, evDigNum = 0, newNum = 0, location = 1, temp;
- System.out.print("Please enter a number: ");
- inputNum = sc.nextInt();
- temp = inputNum; // In order not to destroy the input value
- do {
- if(temp % 2 == 0) { // Check if the number is even. If so add the digit to the number in the right location
- newNum += temp % 10 * location;
- location *= 10;
- }
- temp /= 10; // Omit the right digit
- } while(temp > 0);
- System.out.printf("The even digit number of the number %d is: %d\n", inputNum, newNum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement