Skip to content
Advertisement

How to make equal two char arrays by adding ‘0’? Java

I got some problem. I have two char arrays (for ex. char[] number1 = {‘1′,’1′,’1′,’1’}, and char[] number2 {‘2′,’2’}). And now I want to return array with same length what number1 is, but in indexes on the left where add ‘0’ (for ex. in this case => {‘0′,’0′,’2′,’2’}

I try something like this:

JavaScript

I guess its not hard at all, but im trying hard and there no effect (I try to draw on paper first, everything).

Advertisement

Answer

You can do:

JavaScript

Input 1:

JavaScript

Output 1:

JavaScript

Input 2:

JavaScript

Output 2:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement