Advertisement
javatechie

Reverse number

Aug 28th, 2020
1,529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.37 KB | None | 0 0
  1. package com.javatechie.interview.programming;
  2.  
  3. public class ReverseNumber {
  4.  
  5.     public static int reverse(int no) {
  6.         int temp = 0;
  7.         while (no != 0) {
  8.             temp = temp * 10 + no % 10;
  9.             no = no / 10;
  10.         }
  11.         return temp;
  12.     }
  13.  
  14.     public static void main(String[] args) {
  15.         System.out.println(reverse(123));
  16.     }
  17. }
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement