Tuesday, 27 October 2020

Reverse Number Using do-while loop

Write a Java Program to Reverse Number Using do-while loop 
import java.util.Scanner;
public class ReverseDoWhile 
{
	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;
			do
			{
				reminder=n%10;
				reverse=reverse*10+reminder;
				n=n/10;
			}while(n!=0);
		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

Pattern 31 & 32