How to reverse a number in java?
Very easy to understand.
package com.tech.mindclues; import java.util.Scanner; public class ReverseNumber { public static void main(String args[]){ System.out.println("Enter the number : "); Scanner sc = new Scanner(System.in); int n; int reverse =0; n = sc.nextInt(); int x = n; while(x != 0){ reverse = reverse * 10; reverse = reverse + x%10; x = x/10; } System.out.println("Reverse of entered number is "+reverse); } }
Enter the number : 35441 Reverse of entered number is 14453
post a comment