How to Reverse a number ?- Java Coding Test Question-1

Published: 30 September 2023
on channel: Programming With Vishnu
121
20

Please find the solution below :

public class ReverseNumber {

public int reverseNumber(int num) {
//write your code here
int rev =0;
while(num !=0) {
//access last digit from a number
int ld = num %10; // return reminder
rev = rev*10+ld; // 8*10 + 9 = 89
//remove last digit from a number
num = num/10; // return Qutient
}
return rev;
}
public static void main(String[] args) {
ReverseNumber r = new ReverseNumber();
System.out.println(r.reverseNumber(7896)); // if you want to check other number please
//pleas change 7896 to another num
}
}


On this page of the site you can watch the video online How to Reverse a number ?- Java Coding Test Question-1 with a duration of hours minute second in good quality, which was uploaded by the user Programming With Vishnu 30 September 2023, share the link with friends and acquaintances, this video has already been watched 121 times on youtube and it was liked by 20 viewers. Enjoy your viewing!