-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise5_4.java
More file actions
47 lines (40 loc) · 936 Bytes
/
Exercise5_4.java
File metadata and controls
47 lines (40 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.util.Scanner;
public class Exercise5_4 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a integer: ");
int number = input.nextInt();
reverse(number);
}
public static void reverse(int n) {
String tag = "";
int ch;
if (n < 0) {
tag = "-";
n = -n;
}
System.out.print(tag);
while (n != 0) {
ch = n % 10;
System.out.print(ch);
n = n / 10;
}
System.out.println();
}
}
/*public class Exercise5_4 {
public static void main(String[] args) {
System.out.print("Enter an integer: ");
java.util.Scanner input = new java.util.Scanner(System.in);
int number = input.nextInt();
reverse(number);
}
public static void reverse(int number) {
while (number != 0) {
int remainder = number % 10;
System.out.print(remainder);
number = number / 10;
}
System.out.println();
}
}*/