forked from txs72/JavaTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDec2Hex.java
More file actions
executable file
·37 lines (35 loc) · 1 KB
/
Dec2Hex.java
File metadata and controls
executable file
·37 lines (35 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* */ package ch05;
/* */
/* */ import java.util.Scanner;
/* */
/* */
/* */ public class Dec2Hex
/* */ {
/* */ public static void main(String[] args) {
/* 9 */ Scanner input = new Scanner(System.in);
/* */
/* */
/* 12 */ System.out.print("Enter a decimal number: ");
/* 13 */ int decimal = input.nextInt();
/* */
/* */
/* 16 */ String hex = "";
/* */
/* 18 */ while (decimal != 0) {
/* 19 */ int hexValue = decimal % 16;
/* */
/* */
/* 22 */ char hexDigit = (hexValue <= 9 && hexValue >= 0) ? (char)(hexValue + 48) : (char)(hexValue - 10 + 65);
/* */
/* */
/* 25 */ hex = hexDigit + hex;
/* 26 */ decimal /= 16;
/* */ }
/* */
/* 29 */ System.out.println("The hex number is " + hex);
/* */ }
/* */ }
/* Location: /Volumes/TXS.128G/hope useful/practice/2020.jar!/ch05/Dec2Hex.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/