Skip to content

Commit ee029e7

Browse files
committed
feat: Implement logic to reverse a given number using modulus and division
🧠 Logic: - Extract digits from the number using `% 10`. - Build the reversed number by multiplying `rev` by 10 and adding the digit. - Repeat until the original number becomes 0. - Print the reversed number at the end. Signed-off-by: Somesh diwan <[email protected]>
1 parent d65d4fa commit ee029e7

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

Section8LoopAB/src/ReverseANumber.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//Reverse a number.
2-
31
import java.util.Scanner;
42

53
public class ReverseANumber {
@@ -9,8 +7,7 @@ public static void main(String[] args) {
97
int n = sc.nextInt();
108

119
int rev =0,r;
12-
while (n>0)
13-
{
10+
while (n>0) {
1411
r=n%10;
1512
rev=rev*10+r;
1613
n/=10;

0 commit comments

Comments
 (0)