Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fe7b1dc

Browse files
🍵
1 parent bd997cb commit fe7b1dc

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎challenge22.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import java.util.Scanner;
2+
3+
// Create a program to reverse the digits of a number.🚀
4+
public class challenge22 {
5+
public static void main(String[] args) {
6+
Scanner sc = new Scanner(System.in);
7+
System.out.println("Welcome to Reverse Digits!");
8+
System.out.print("Enter a number: ");
9+
int num = sc.nextInt();
10+
int reversedNum = reverseDigits(num);
11+
System.out.println("Reversed digits: " + reversedNum);
12+
}
13+
14+
public static int reverseDigits(int num) {
15+
int reversedNum = 0;
16+
while (num != 0) {
17+
int digit = num % 10;
18+
reversedNum = reversedNum * 10 + digit;
19+
num /= 10;
20+
}
21+
return reversedNum;
22+
}
23+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /