IntegerPrinter.java 823B

123456789101112131415161718192021222324252627282930313233
  1. import java.util.Scanner;
  2. import java.lang.Math;
  3. public class IntegerPrinter {
  4. int value = 0;
  5. public static String printIntegerAsBinary(int value){
  6. String binary = Integer.toBinaryString(value);
  7. return binary;
  8. }
  9. public static String printIntegerAsOctal(int value){
  10. String octal = Integer.toOctalString(value);
  11. return octal;
  12. }
  13. public static String printIntegerAsHexadecimal(int value){
  14. String hex = Integer.toHexString(value);
  15. return hex;
  16. }
  17. public static void main(String[] args){
  18. Scanner in = new Scanner(System.in);
  19. System.out.println("Please enter a number:");
  20. int i = in.nextInt();
  21. printIntegerAsBinary(i);
  22. printIntegerAsOctal(i);
  23. printIntegerAsHexadecimal(i);
  24. }
  25. }