java - Conversion numbers systems provides incorrect result -
i write programme convert number systems. want convert decimal duodecimal.
start value: 123. expected output: a3
unfortunately not right result. why? not understand error?
can help me , explain error?
public static string dezitoduo(string duo) { string s = "0123456789abcdef"; int rest; string result = ""; boolean break = true; int changetoint = integer.parseint(duo); while (break) { rest = changetoint % 12; char c = (char) s.indexof(rest); stringbuilder sb = new stringbuilder(c); result = sb.reverse().tostring(); changetoint = changetoint / 12; if (changetoint == 0){ break = false; } } homecoming result; }
there couple of problems here:
break
reserved keyword in java, alter name of variable else. you overwriting sb
each iteration. should create before loop , utilize illustration insert()
insert next character first in result. you using indexof()
instead of charat()
i'll leave implement changes.
java eclipse
No comments:
Post a Comment