Java Program to Reverse a Number

preview_player
Показать описание
In this Java Video Tutorial you will learn How to Write a Program to Reverse a Number entered by the user.

Here we ask the user to enter a number and then we separate each digits from that number, and generate the number which will be the reverse of the given number.

This program can help a beginner in Computer Programming to understand how to construct the logic, How to use loops effectively.

our Social Media Pages

Our Website

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

Best explanation I've seen now. Thank you.

AdrianTregoning
Автор

THANK YOU!!! this is the only video i found that explains this problem!! thanks sir (edit: i found many videos that just show you the code but don't say anything about how it works).

dudem
Автор

how can we do this with for loop? as we have to mention the initial value and then increment or decrement too

paramgandhi
Автор

Very good explanation i understand easily through ur bref explanation.thank you Very much

Anil_Y_channel
Автор

thanks! you're amazing at explaining :)

rstikh
Автор

public class exercise {
public static void main(String[] args)
{
int remainder, revNumber = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a three digit number(100 to 999)");
int number = sc.nextInt();

if (number > 99 && number < 1000) {
while (number > 0) {
remainder = number % 10;
number = number / 10;
revNumber = (revNumber * 10) + remainder;
}

}
else {
System.out.println("It is not a three digit number");
System.exit(0);

}
}

nsnikhil