Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

File - C:\Users\daria\OneDrive\Programming\GitHub\Java\JavaPractice\src\ReverseInt.

java
1 import java.util.Scanner;
2
3 public class ReverseInt {
4
5
6     public static void main(String[] args) {
7         Scanner input = new Scanner(System.in);
8         int number = input.nextInt();
9
10         System.out.println(reverse(number));
11
12     }
13
14     public static int reverse(int num) {
15
16         int reversed = 0;
17
18         while (num!=0){
19             reversed = reversed*10 + num%10; // 0*10 + 35%10 = 5
    // 5*10 + 35%10 = 53.5
20             num /= 10; // 35/10 = 3.5    //  3.5/10 = 0.35 stops
21
22         }
23         return reversed;
24     }
25
26
27 }
28

Page 1 of 1

You might also like