-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchallenge22.java
More file actions
23 lines (21 loc) · 812 Bytes
/
challenge22.java
File metadata and controls
23 lines (21 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.util.Scanner;
// Create a program to reverse the digits of a number.🚀
public class challenge22 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Welcome to Reverse Digits!");
System.out.print("Enter a number: ");
int num = sc.nextInt();
int reversedNum = reverseDigits(num);
System.out.println("Reversed digits: " + reversedNum);
}
public static int reverseDigits(int num) {
int reversedNum = 0;
while (num != 0) {
int digit = num % 10;
reversedNum = reversedNum * 10 + digit;
num /= 10;
}
return reversedNum;
}
}