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