Computer Science, asked by shahid22aziz, 1 year ago

write an algorithm to print multiplication table of a number in reverse order

Answers

Answered by kirahinamoriamuchan
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