Java Program to Reverse a Number
ฝัง
- เผยแพร่เมื่อ 16 ก.ย. 2024
- 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
/ exampleprogram
/ exampleprogram
/ example_program
Our Website
www.ExamplePro...
#JavaProgramming #ExampleProgram
Best explanation I've seen now. Thank you.
You're very welcome!
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).
You're welcome!
Very good explanation i understand easily through ur bref explanation.thank you Very much
You are most welcome
thanks! you're amazing at explaining :)
Glad you think so!
Good work.
Thanks!
❤❤❤❤goat
thanks :)
Thank you
You're welcome
Thank u sir
Welcome
Good video
Thank you :)
Nice bro
Thanks
how can we do this with for loop? as we have to mention the initial value and then increment or decrement too
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;
}
System.out.println(revNumber);
}
else {
System.out.println("It is not a three digit number");
System.exit(0);
}
}
only issue with this is, it does not ask you to enter a number again. it stops running after sending the message it is not a three digit number.
iterate again in while loop to ask for the user input again
why we are using 10?
decimal number system.
it has 10 digits ( 0 - 9 )
Why we dividing with 10
to remove remainder
Why we multiply by 10
because here we are using decimal number system :)
@@ExampleProgram thank you 👍
1 error in programm example like 1000