Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- modemnoise.blogspot.com
- Simple program to print out the Printable characters in ASCII.
- Print int value, character and hex value
- Test if Java identifier and legal start of
- java identifier
- */
- class chartest {
- public static void main(String[] args) {
- System.out.println();
- System.out.println("Int\tChar\tHex\tJava\tJavStart");
- System.out.println("----------------------------------------");
- // Loop through the printable charaters of the ASCII table
- // Printable character go from 33 == '!' to 126 == '~'
- for (int i = 33; i < 127; i++){
- // Example of some formatting argumentss and flags
- // 1$ references 1st attribute 2$ the second etc
- // 04d formats an integral value 4 chars wide with 0s padding to left
- // 04X formats a hex value in uppercase 4 chars wide with 0s padding to left
- // 04x would do the same as above but with lowercase hex
- // Note the 0x in the example below is printed data not reference to attribute
- System.out.printf("%1$04d\t%1$c\t0x%1$04X\t", i);
- // Outer if using the Character wrapper class to test
- // if character can be used in a Java identifier
- if (Character.isJavaIdentifierPart(i)){
- System.out.print("y\t");
- // Nested if using the Character wrapper class to test
- // if character can be used to start a Java identifier
- // Nested as no point testing if not a legal character
- // for Java identifier.
- if (Character.isJavaIdentifierStart(i)){
- System.out.print("y");
- } //inner if
- } //outer if
- // new line after each iteratiion of loop
- System.out.println();
- }//for
- } //main
- }//class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement