Sunday, May 12, 2019

how will you reverse the number?

Problem statement:
how do you reverse the given number?
  1. class A {
  2.     public static void main(String args[]) {
  3.         int n = 243589;
  4.         int r = 0;
  5.         while (n != 0) {
  6.             r = r * 10 + n % 10;
  7.             n = n / 10;
  8.         }
  9.         System.out.println(r);
  10.     }
  11. }
Output:
985342
Asked in - Synechron technologies

No comments:

Post a Comment

Blueprint for self-improvement

To learn faster: Make the process fun To understand yourself : Write To understand the world better : Read To build deeper connection : Lis...