Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner s = new Scanner(System.in);
- int num1,num2,temp1,temp2,finalnum=0,count1=1,count2=1;
- System.out.println("Enter 2 numbers with eqal lenght");
- num1 = s.nextInt();
- num2 = s.nextInt();
- temp1=num1;//*set new int that store the original numbers..
- temp2=num2;//*so we can run tests without losing them
- while(temp1/10!=0){
- count1++;
- temp1/=10;
- } //*we /10 the numbers and add 1 to count as long as it happens
- while(temp2/10!=0){
- count2++;
- temp2/=10;
- }
- if(count1==count2){ //* we check if the numbers are equal in length by comparing the counts
- count1=1;//*if Condition is met we set the count in position 1
- while(num2!=0){//*as long as num2 its not zero we have numbers left in it
- finalnum+=(num2%10)*count1;//*we build the number from right to left
- count1*=10;//*change the position by 10
- num2=num2/10;//* /10 the number to keep going until its 0
- finalnum+=(num1%10)*count1;
- count1*=10; //*same process as we did to num2
- num1=num1/10;
- }
- }
- else {
- System.out.println("The numbers was not equal in length");
- //* if the counts we set wasnt equal the user didnt follow the instructions
- }
- System.out.println("NEW number is :"+finalnum);
- //* we print the new mixed number
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement