I have the following code to reverse the digits in an integer:
public class integerReversal {
public static int reverseNum(int number){
int reversed = 0;
int remainder;
//{I: ; B: number > 0}
while (number > 0){
remainder = number % 10;
number = number / 10;
reversed = reversed * 10 + remainder;
}
//{I: ; !B: number == 0}
return reversed;
}
public static void main (String [] args){
System.out.println(reverseNum(1262015 ));
}
}
My professor tasked us with writing this code and also said to write the loop invariant and loop condition. I understand the loop condition here, I'm just unsure what I should be looking at for the invariant. I realize that it is some condition that will be true at the beginning and end of the while loop, for every iteration, I just do not see what it would be here. Tips would be appreciated.