write an algorithm to print multiplication table of a number in reverse order
Answers
Answered by
8
public class ReverseNumber {
public static void main(String[] args) {
int num = 34658;
int reversedNum = reverseNum(num);
System.out.println(reversedNum);
}
public static int reverseNum(int num) {
int reversedNum = 0;
boolean isNegative = (num < 0);
num = Math.abs(num);
while (num > 0) {
int digit = num % 10;
num /= 10;
reversedNum *= 10;
reversedNum += digit;
}
return isNegative ? -reversedNum : reversedNum;
}
}
Similar questions