Advertisement
eranseg

EvenDigitsNumber

Jul 28th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class EvenDigits {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner sc = new Scanner(System.in);
  7.         int inputNum, evDigNum = 0, newNum = 0, location = 1, temp;
  8.         System.out.print("Please enter a number: ");
  9.         inputNum = sc.nextInt();
  10.         temp = inputNum; // In order not to destroy the input value
  11.         do {
  12.             if(temp % 2 == 0) { // Check if the number is even. If so add the digit to the number in the right location
  13.                 newNum += temp % 10 * location;
  14.                 location *= 10;
  15.             }
  16.             temp /= 10; // Omit the right digit
  17.         } while(temp > 0);
  18.         System.out.printf("The even digit number of the number %d is: %d\n", inputNum, newNum);
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement