Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class q1 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner S= new Scanner(System.in);
- System.out.println("enter number:");
- int userNum= S.nextInt(); //the user enter number
- int indexNewNum= 1; // installed indexer to the result number
- int newNum=0; // installed the result number
- int num=userNum; // installed the helper variable <-- userNum
- final int MOOD=2; // installed the number of the division <-- 2
- while (num>0) { // run as long as num up to 0
- int moodNum= num%10; // installed helper variable <-- the right digit
- if(moodNum%MOOD==0){ // if the left digit is double
- newNum+=indexNewNum*moodNum; //the right digit add to the result number to the left
- indexNewNum*=10; // the indexer double by 10
- }
- num/=10; // remove the right digit
- }
- System.out.println("the new number is: "+newNum); // print the result
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement