Write a Java Program to Reverse Number Using method
import java.util.Scanner; public class ReverseUsingMethod { void reverse() { int reminder,reverse=0,temp; Scanner scan = new Scanner(System.in); System.out.println("\n\nEnter a Number: "); int n = scan.nextInt(); temp=n; while(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); } public static void main(String[] args) { ReverseUsingMethod obj = new ReverseUsingMethod(); obj.reverse(); } }
Output:
Enter a Number: 159874632
No comments:
Post a Comment
If you have any doubts, please let me know