java - How to print out a negative number represented by an array -


i'm starting learn java, , want try represent big negative numbers using arrays.

let's have array

[-2, 0, -5] , represents number -502 

i've tried using stringbuilder, prints out

-50-2 

this code of right now. there way make can append first negative, , skip rest of negatives when building new string?

    stringbuilder sb = new stringbuilder();      for(int x = arr.length-1; x>=0; x--){         sb.append(arr[x]);     }     string check = sb.tostring();     system.out.println(check); 

initialize string buffer last character (with appropriate sign) , ignore signs rest.

stringbuilder sb = new stringbuilder(); sb.append(arr[length-1]);  (int x = arr.length-2; x>=0; x--) {     sb.append(math.abs(arr[x])); } string check = sb.tostring(); system.out.println(check); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -