IntegerPrinter.java 902B

12345678910111213141516171819202122232425262728293031323334353637
  1. import java.lang.StringBuilder;
  2. import java.lang.*;
  3. //import java.lang.Integer.toOctalString();
  4. //import java.lang.Integer.toHexString();
  5. public class IntegerPrinter {
  6. public String printIntegerAsBinary(int value){
  7. StringBuilder build = new StringBuilder();
  8. while(value != 0)
  9. {
  10. build.insert(0,value % 2);
  11. value = value / 2;
  12. }
  13. return build.toString();
  14. }
  15. public String printIntegerAsOctal(int value){
  16. StringBuilder build = new StringBuilder();
  17. String newString = Integer.toOctalString(value);
  18. return newString;
  19. }
  20. public String printIntegerAsHexadecimal(int value){
  21. StringBuilder build = new StringBuilder();
  22. String newString = Integer.toHexString(value);
  23. return newString;
  24. }
  25. public static void main(String[] args){
  26. }
  27. }