Reverse a number
Write a program to generate the reverse of a given number N. Print the corresponding reverse number.
Note : If a number has trailing zeros, then its reverse will not include them. For e.g., reverse of 10400 will be 401 instead of 00401.
Input format :
Integer N
Output format :
Corresponding reverse number
Constraints:
0 <= N < 10^8
CodingNinjas
author
2y
To reverse a number following steps should be performed:
Take the number’s modulo by 10
Multiply the reverse number by 10 and add modulo value into the reverse number.
Divide the number by 10.
Repeat abov...read more
CodingNinjas
author
2y
Space Complexity: O(1)Explanation: Time Complexity: O(1)Explanation:
surbhi kumari
1y
Scanner s = new Scanner(System.in); int n = s.nextInt(); int rev =0; int rem =0; while(n>0){ rem = n%10; rev = (rev*10) + rem; n=n/10; } System.out.println(rev);
Add answer anonymously...
Top Juniper Networks Software Engineer interview questions & answers
Popular interview questions of Software Engineer
Top HR questions asked in Juniper Networks Software Engineer
>
Juniper Networks Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app