Reverse number in java very simple logic for beginners.

preview_player
Показать описание
in this video, I explain how to reverse number with simple logic for beginners;

public class ReverseNumber {

public static void main(String[] args) {

int num = 1234, reversed = 0;

while(num != 0) {
int digit = num % 10;
reversed = reversed * 10 + digit;
num /= 10;
}

}
}
Рекомендации по теме
Комментарии
Автор

Nice explanation...thanks very informative.

yogeshkhond
Автор

Thank you so much sir very good explication

yasminalazizi
Автор

The code doesn’t work when the digit is more than 2

biliaminjimoh
Автор

Finally Got it Sir❤❤ Loves From Myanmar❤

theyouthmedia
Автор

what was the point of writing reverse = reverse * 10 +remainder;? and why while(number>=1) and not 10¿

mitskienjoyer
Автор

Than you very much sir and then you explanation excellent, ,

ganeshc
Автор

You could use (number !=0) its more convenient

MN-lgxk
Автор

If I import scanner will this program will work

hemanthkumar
Автор

what should i do if integer ends with 0, let's say 123000. Thanks

mzhdbszhxhzb
Автор

This won’t work with numbers ending in 0

GlimmArin