/home/caleb/ASDV-Java/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/DecimalToHex1.java |
nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt
nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java
package com.calebfontenot.lab8_calebfontenot;
import java.util.Scanner;
public class DecimalToHex1 {
public static void main(String[] args) {
int inputDecimal,
outputHex = 0x0;
Scanner input = new Scanner(System.in);
System.out.print("Enter a decimal value (0-15): ");
inputDecimal = input.nextInt();
switch (inputDecimal) {
case 0:
outputHex = 0x0; break;
case 1:
outputHex = 0x1; break;
case 2:
outputHex = 0x2; break;
case 3:
outputHex = 0x3; break;
case 4:
outputHex = 0x4; break;
case 5:
outputHex = 0x5; break;
case 6:
outputHex = 0x6; break;
case 7:
outputHex = 0x7; break;
case 8:
outputHex = 0x8; break;
case 9:
outputHex = 0x9; break;
case 10:
outputHex = 0xA; break;
case 11:
outputHex = 0xB; break;
case 12:
outputHex = 0xC; break;
case 13:
outputHex = 0xD; break;
case 14:
outputHex = 0xE; break;
case 15:
outputHex = 0xF; break;
}
System.out.println("The hex value is " + String.format("%x", outputHex));
}
}