-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheight.java
More file actions
22 lines (21 loc) · 728 Bytes
/
eight.java
File metadata and controls
22 lines (21 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//Write a program to reverse the digits of a numbers.
import java.util.Scanner;
public class eighth {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter an integer: ");
int number = scanner.nextInt();
int reversed = 0;
int original = number;
int temp = Math.abs(number);
while (temp > 0) {
int digit = temp % 10;
reversed = reversed * 10 + digit;
temp /= 10;
}
if (original < 0) {
reversed *= -1;
}
System.out.println("Reversed number: " + reversed);
}
}