Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Exercise4_11DecimalToHex {
- public static void main(String[] args) {
- Scanner kb = new Scanner(System.in);
- System.out.println("Enter a number from 0-15");
- int number = kb.nextInt();
- if (number < 0 || number > 15)
- System.out.println("invalid input");
- else if (number < 10)
- System.out.println("the hex of this number is "+number);
- else{
- char ch = (char)('A' -10 + number);
- System.out.println("the hex of this number is "+ch);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment