therrontelford

Decimal to Hex

Nov 14th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.51 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Exercise4_11DecimalToHex {
  3.  
  4.     public static void main(String[] args) {
  5.         Scanner kb = new Scanner(System.in);
  6.         System.out.println("Enter a number from 0-15");
  7.         int number = kb.nextInt();
  8.        
  9.         if (number < 0 || number > 15)
  10.             System.out.println("invalid input");
  11.         else if (number < 10)
  12.             System.out.println("the hex of this number is "+number);
  13.         else{
  14.             char ch = (char)('A' -10 + number);
  15.                     System.out.println("the hex of this number is "+ch);
  16.         }
  17.  
  18.     }
  19.  
  20. }
Advertisement
Add Comment
Please, Sign In to add comment