YavorGrancharov

Integer_to_Hex_and_Binary

Jan 4th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Integer_to_Hex_and_Binary {
  4.     public static void main(String[] args) {
  5.  
  6.         DecimalToHex hex = new DecimalToHex();
  7.  
  8.         hex.getVal();
  9.         hex.convert();
  10.  
  11.         DecimalToBinary bin = new DecimalToBinary();
  12.  
  13.         bin.getVal();
  14.         bin.convert();
  15.     }
  16.     public static class DecimalToHex {
  17.  
  18.         int num;
  19.  
  20.         void getVal() {
  21.  
  22.             Scanner console = new Scanner(System.in);
  23.  
  24.             num = Integer.parseInt(console.nextLine());
  25.         }
  26.  
  27.         void convert() {
  28.  
  29.             String hex = Integer.toHexString(num);
  30.  
  31.             System.out.println(hex.toUpperCase());
  32.         }
  33.     }
  34.     public static class DecimalToBinary {
  35.  
  36.         int num;
  37.  
  38.         void getVal() {
  39.  
  40.             Scanner console = new Scanner(System.in);
  41.  
  42.             num = Integer.parseInt(console.nextLine());
  43.         }
  44.  
  45.         void convert() {
  46.  
  47.             String binary = Integer.toBinaryString(num);
  48.  
  49.             System.out.println(binary);
  50.         }
  51.     }
  52. }
Add Comment
Please, Sign In to add comment