employer cover photo
employer logo

Pregunta de entrevista de Rubicon Project

Given an integer like 543, write a function to return String "500+40+3" and test your code

Respuesta de la entrevista

Anónimo

22 ago 2017

import java.lang.*; public class Test{ public static void main(String []args){ int num = 543; int len = String.valueOf(num).length(); String s[] = new String[len]; int p =0; while (num != 0){ int i = num%10; num = num/10; int k = i * (int) Math.pow(10,p); s[p] = Integer.toString(k); p++; } for(int i = len-1; i>=0; i--) System.out.print(s[i]+ "+"); System.out.println(); } }