java - string builder and string output -
although have converted output string
, output on console "solution@3343c8b3". thanks.
public class solution { public string converttotitle(int n) { if (n < 1) throw new illegalargumentexception("input wrong number"); stringbuilder sb = new stringbuilder(); while (n > 0) { n--; char ch = (char) (n % 26 + 'a'); n = n / 26; sb.append(ch); } sb.reverse(); return sb.tostring(); } }
the test class:
public class test { public static void main(string[] args) { int f = 2; solution f1 = new solution(); f1.converttotitle(f); system.out.println(f1); } }
you should print value returned method : converttotitle
:
string title = f1.converttotitle(f); system.out.println(title);
also, this might not concern @ time, system.out.println(f1);
printing string provided default implementation of tostring
in object
class.
you should override tostring
method in solution
.
Comments
Post a Comment