/** * Prints out ASCII characters in a table to demonstrate their unsigned integer * equivalents. * @author Sarah Larkin * CS3090, Spring 2018 * Date Last Modified: March 3, 2018 */ public class ASCII_Viewer { public static void main(String[] args) { ASCII_Viewer self = new ASCII_Viewer(); self.printAllACSII(); self.printDisplayableASCII(); /* Print a "character" that is out of the ASCII range * It displays as a question mark. */ System.out.println("128: " + (char)128); // Print out the sum of 'a' + 'A' System.out.println("a + A = " + self.sumASCII('a', 'A')); // Print out the product of 'a' + 'A' System.out.println("a * A = " + 'a' * 'A'); } /** * Prints out all 128 ASCII characters - 63 is authentically the question mark */ public void printAllACSII() { System.out.println("All ASCII characters"); for (int i = 0; i < 128; i++) { System.out.print(i + ": " + (char)i + " "); // Print a new line after every five characters if (i > 0 && i % 5 == 0) { System.out.println(); } } System.out.println(); } /** * Prints out only the displayable ASCII characters */ public void printDisplayableASCII() { System.out.println("Displayable ASCII characters"); for(int i = 32; i < 127; i++) { System.out.print(i + ": " + (char)i + "\t"); // Print a new line after every five characters if ((i - 31) % 5 == 0) { System.out.println(); } } } /** * Adds two characters together and returns the value as an int * @param ch1 the first character * @param ch2 the second character * @return the sum as an integer */ public int sumASCII(char ch1, char ch2) { return ch1 + ch2; } }