/home/caleb/ASDV-Java/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/DecimalToHex2.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 DecimalToHex2 {
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();
if (inputDecimal == 0) {
outputHex = 0x0;
} else if (inputDecimal == 1) {
outputHex = 0x1;
} else if (inputDecimal == 2) {
outputHex = 0x2;
} else if (inputDecimal == 3) {
outputHex = 0x3;
} else if (inputDecimal == 4) {
outputHex = 0x4;
} else if (inputDecimal == 5) {
outputHex = 0x5;
} else if (inputDecimal == 6) {
outputHex = 0x6;
} else if (inputDecimal == 7) {
outputHex = 0x7;
} else if (inputDecimal == 8) {
outputHex = 0x8;
} else if (inputDecimal == 9) {
outputHex = 0x9;
} else if (inputDecimal == 10) {
outputHex = 0xA;
} else if (inputDecimal == 11) {
outputHex = 0xB;
} else if (inputDecimal == 12) {
outputHex = 0xC;
} else if (inputDecimal == 13) {
outputHex = 0xD;
} else if (inputDecimal == 14) {
outputHex = 0xE;
} else if (inputDecimal == 15) {
outputHex = 0xF;
}
System.out.println("The hex value is " + String.format("%x", outputHex));
}
}