employer cover photo
employer logo
employer logo

Huawei Technologies

Is this your company?

Huawei Technologies Interview Question

Given a decimal number, compute the reverse.

Interview Answer

Anonymous

Sep 2, 2022

// Java program to reverse a number class GFG { /* Iterative function to reverse digits of num*/ static int reverseDigits(int num) { int rev_num = 0; while (num > 0) { rev_num = rev_num * 10 + num % 10; num = num / 10; } return rev_num; } // Main Function public static void main(String[] args) { int num = 4562; System.out.println("Reverse of num --> " + reverseDigits(num)); } }