java - How to find what value this code returns without a computer? -


what value mystery(12345678) return?

public string mystery(int n)  {  string soln = “”;  while (n > 0)  {  soln = n % 10 + soln;  n = n / 100;  }  return soln;  } 

the answers are: a) “1357” b) “2468” c) “7531” d) “8642” e) causes run-time error.

edit: know answer b) compiling not sure how works.

you can see it's loop of adding one's digit of n first index of string, dividing n 100. eventually, 2468


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -