How To Print A Reverse Int In Java Code Example

Snippet 1

  public class ReverseNumber {
    public static void main(String[] args) {
        int num = 1234, reversed = 0;

        while(num != 0) {
            int digit = num % 10;
            reversed = reversed * 10 + digit;
            num = num / 10;
        }
        System.out.println("Reversed Number: " + reversed);
}} 

Copyright © Code Fetcher 2020

 

 

Published

Leave a comment

Your email address will not be published. Required fields are marked *