If a five-digit number is input through the keyboard, write a program to reverse the number.
import java.util.Scanner; class Reverse_Digits { public static void main(String args[]) { Scanner input = new Scanner(System.in); System.out.println("Enter the Five Digits Numbers :"); int num = input.nextInt(); System.out.println("Before Reverse :"+num); int rem,rev=0; rem=num%10; num=num/10; rev=rev+rem*10000; rem=num%10; num=num/10; rev=rev+rem*1000; rem=num%10; num=num/10; rev=rev+rem*100; rem=num%10; num=num/10; rev=rev+rem*10; rem=num%10; rev=rev+rem; System.out.println("After Reverse :"+rev); } }
Enter the Five Digits Numbers : 58624 Before Reverse :58624 After Reverse :42685
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions