How can I cache the original digits I removed in a modulo action, so they can subsequently be restored after substituting a digit with another digit?
Example:
Public void setDigit(int number, int place, int newdigit) {
Int num = number;
Int k = place;
Int newDigit = newdigit;
For(int x = 0; x<k; x++) {
Num/=10;
}
Num%=10;
Num = newDigit
}
Please help thanks in advance.
If I understood your question correctly, if
num = 1234for example you want to find123when you take the modulo of 10.To do this you can simply use
num / xwherenumis anintandxis anintwhich euqls the modulo you just used.So in this case
num %= 10givesnum = 4. But if we didnum / 10first then we would get123.