I'm writing a code in Java where input is a user generated integer string and I have to reverse the integer and check for boolean true or not. I'm stuck at the math portion because I can't exactly figure out the mathematical process of trying to reverse an integer.
// Scanner
Scanner input = new Scanner(System.in);
System.out.print("Please enter an integer: ");
int number = input.nextInt();
// Initialize variables
int d = number;
int i = reverse(d);
int j = isPalindrome(d);
}
// Reverse Method
public static int reverse(int d){
for (int i = 0; i <= d; i++){
int r = d % 10;
d = d / 10;
}
}
I don't know if I should use a while loop or a for loop. But that's where my code is right now.