3

How to Reverse a Number in Java

 2 years ago
source link: https://www.geeksforgeeks.org/videos/how-to-reverse-a-number-in-java/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to Reverse a Number in Java

How to Reverse a Number in Java
Hello everyone. Welcome to Geeks for geeks. And the
  • 10/07/2022

In this video, we will learn the Java program on how to reverse a number.

Here, we reverse a number using two different methods: 1. Using While loop 2. Using recursion function

A loop is a part of a computer program that allows a certain set of instructions to be executed repeatedly. A loop is created by enclosing the set of instructions inside a block of code called a bracket and throwing in the keyword while.

Using While loop: 1) Take the number’s modulo by 10. 2) Multiply the reverse number by 10 and add a modulo value to the reverse number. 3) Divide the number by 10. 4) Repeat the above steps until the number becomes zero.

Using recursion function: The recursion operator in Java allows you to repeat an instruction or statement a set number of times. 1) If the number becomes zero then terminate the recursion, this will be the base condition. 2) Take the modulo and add it with the ‘rev*10’ multiplying. 3) Divide the number by 10 and call the reverse function on this number after updating it to number/10.

Java Program to Reverse a Number: https://www.geeksforgeeks.org/java-program-to-reverse-a-number/


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK