Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,926 questions

51,859 answers

573 users

How to display the 128 values ASCII table using Java

1 Answer

0 votes
package javaapplication1;

public class JavaApplication1 {

    public static void main(String[] args) {

        try {

            System.out.printf("%1$-8s %2$-10s %3$s\n", "Decimal", "ASCII", "Hex");

            for (int i = 0; i < 128; i++) {
                char ch = (char) i;
                String show = "";
                if (Character.isWhitespace(ch)) {
                    switch (ch) {
                        case '\n':
                            show = "\\n";
                            break;
                        case '\r':
                            show = "\\r";
                            break;
                        case '\t':
                            show = "\\t";
                            break;
                        case '\f':
                            show = "\\f";
                            break;
                        case ' ':
                            show = "space";
                            break;
                        default:
                            show = "whitespace";
                            break;
                    }
                } else if (Character.isISOControl(ch)) {
                    show = "ctrl code";
                } else {
                    show = Character.toString(ch);
                }
                System.out.printf("%1$-8d %2$-10s %3$s\n", i, show, Integer.toHexString(i));
            }

        } catch (Exception e) {
            System.out.print(e.toString());
        }
    }
}

/*
             
run:

Decimal  ASCII      Hex
0        ctrl code  0
1        ctrl code  1
2        ctrl code  2
3        ctrl code  3
4        ctrl code  4
5        ctrl code  5
6        ctrl code  6
7        ctrl code  7
8        ctrl code  8
9        \t         9
10       \n         a
11       whitespace b
12       \f         c
13       \r         d
14       ctrl code  e
15       ctrl code  f
16       ctrl code  10
17       ctrl code  11
18       ctrl code  12
19       ctrl code  13
20       ctrl code  14
21       ctrl code  15
22       ctrl code  16
23       ctrl code  17
24       ctrl code  18
25       ctrl code  19
26       ctrl code  1a
27       ctrl code  1b
28       whitespace 1c
29       whitespace 1d
30       whitespace 1e
31       whitespace 1f
32       space      20
33       !          21
34       "          22
35       #          23
36       $          24
37       %          25
38       &          26
39       '          27
40       (          28
41       )          29
42       *          2a
43       +          2b
44       ,          2c
45       -          2d
46       .          2e
47       /          2f
48       0          30
49       1          31
50       2          32
51       3          33
52       4          34
53       5          35
54       6          36
55       7          37
56       8          38
57       9          39
58       :          3a
59       ;          3b
60       <          3c
61       =          3d
62       >          3e
63       ?          3f
64       @          40
65       A          41
66       B          42
67       C          43
68       D          44
69       E          45
70       F          46
71       G          47
72       H          48
73       I          49
74       J          4a
75       K          4b
76       L          4c
77       M          4d
78       N          4e
79       O          4f
80       P          50
81       Q          51
82       R          52
83       S          53
84       T          54
85       U          55
86       V          56
87       W          57
88       X          58
89       Y          59
90       Z          5a
91       [          5b
92       \          5c
93       ]          5d
94       ^          5e
95       _          5f
96       `          60
97       a          61
98       b          62
99       c          63
100      d          64
101      e          65
102      f          66
103      g          67
104      h          68
105      i          69
106      j          6a
107      k          6b
108      l          6c
109      m          6d
110      n          6e
111      o          6f
112      p          70
113      q          71
114      r          72
115      s          73
116      t          74
117      u          75
118      v          76
119      w          77
120      x          78
121      y          79
122      z          7a
123      {          7b
124      |          7c
125      }          7d
126      ~          7e
127      ctrl code  7f
    
 */

 



answered Nov 30, 2016 by avibootz

Related questions

1 answer 94 views
1 answer 617 views
1 answer 208 views
1 answer 185 views
1 answer 187 views
...