forked from txs72/JavaTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHexDigit2Dec.java
More file actions
executable file
·38 lines (36 loc) · 1.24 KB
/
HexDigit2Dec.java
File metadata and controls
executable file
·38 lines (36 loc) · 1.24 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
38
/* */ package ch04;
/* */
/* */ import java.util.Scanner;
/* */
/* */ public class HexDigit2Dec {
/* */ public static void main(String[] args) {
/* 7 */ Scanner input = new Scanner(System.in);
/* 8 */ System.out.print("Enter a hex digit: ");
/* 9 */ String hexString = input.nextLine();
/* */
/* */
/* 12 */ if (hexString.length() != 1) {
/* 13 */ System.out.println("You must enter exactly one character");
/* 14 */ System.exit(1);
/* */ }
/* */
/* */
/* 18 */ char ch = Character.toUpperCase(hexString.charAt(0));
/* 19 */ if (ch <= 'F' && ch >= 'A') {
/* 20 */ int value = ch - 65 + 10;
/* 21 */ System.out.println("The decimal value for hex digit " + ch + " is " + value);
/* */
/* */ }
/* 24 */ else if (Character.isDigit(ch)) {
/* 25 */ System.out.println("The decimal value for hex digit " + ch + " is " + ch);
/* */ }
/* */ else {
/* */
/* 29 */ System.out.println(ch + " is an invalid input");
/* */ }
/* */ }
/* */ }
/* Location: /Volumes/TXS.128G/hope useful/practice/2020.jar!/ch04/HexDigit2Dec.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/