Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Neo {
- public static void main(String[] args) {
- Scanner s = new Scanner(System.in);
- //ask user for a number
- System.out.println("Enter a number:");
- //get a number from the user
- int myNumber = s.nextInt();
- //set a temporary number
- int temp = myNumber;
- //set the result number
- int resultNumber=0;
- //set the posion 1-x 10-X0 100-X00
- int position=1;
- //while temp is not zero (we still have a numbers inside)
- while (temp!=0)
- {
- //if %10 and after that %2 equal zero, the last digit is odd
- if (temp%10%2==0){
- //add the digit to it's position
- resultNumber+=temp%10*position;
- //move the position to the next position , x->XX
- position*=10;
- //take out the last digit
- temp/=10;
- } else {
- //if the number is not odd, just divide by 10 to take out the digit
- temp/=10;
- }
- }
- System.out.println("Result:"+resultNumber);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement