Write a Java Program to Reverse Number Using for loop
import java.util.Scanner; public class ReverseUsingFor { public static void main(String[] args) { int reminder,reverse=0,temp; Scanner scan = new Scanner(System.in); System.out.println("\n\nEnter a Number: "); int n = scan.nextInt(); temp=n; for( ; n!=0 ; ) { reminder=n%10; reverse=reverse*10+reminder; n=n/10; } System.out.println("\n Given Number:-"+temp); System.out.println("\n After Reverse :-" + reverse); } }
Output:
Enter a Number:
159874632
Given Number:-159874632
After Reverse :-236478951
No comments:
Post a Comment
If you have any doubts, please let me know