I am working on a simple program and I need to swap the tens digits of two numbers with conditions. If the tens digit of num1 is larger than the tens digit of num2, then return num1. If the tens digit of num1 is less than the tens digit of num2 then swap the tens digits and print num1 (with the swapped tens digit). Example : 987 123
returns 987 and 234 356
returns 254.
Here is my code so far:
public int swapForBigTensPlace (int num1, int num2)
{
int swap;
int a = num1%10;
int b = num1/10%10;
int c = num1/100%10;
int a1 = num2%10;
int b1 = num2/10%10;
int c1 = num2/100%10;
if(b>b1)
return num1;
else if(b1 > b)
swap = supposed to be a, b1, and c next to each other;
return swap;
}
I don't know how to make it so that it will return three ints next to each other, and not add them. Please show me how to do this. Thank you!
You do want to add them. You just need to undo the math you originally did for those numbers. Like this:
swap = (a * 100) + (b1 * 10) + c