Tuesday, 27 October 2020

Reverse Number without user interaction

Write a Java Program to Reverse Number without user interaction 

public class ReverseNumberWithoutUserInteraction 
{
	public static void main(String[] args) 
	{
		int number=159623487;
		int reminder;
		int reverse=0;
		int temp=number;
		while(number!=0)
		{
			reminder=number%10;
			reverse=reverse*10+reminder;
			number=number/10;
		}
		System.out.println("\n\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