// // File: /home/cs255001/demo/atoi/JavaInput_2.java // // Demo String = array of ASCII codes // public class JavaInput_2 { public static void main(String[] args) throws Exception { byte[] b = new byte[100]; int count; while ( true ) { System.out.print("Enter input: "); count = System.in.read(b); // Read from key board System.out.println("# characters read = " + count); for (int i = 0; i < count; i++) { System.out.println(b[i]); // System.out.println(String.format("%x", b[i]) ); // Print in Hex } System.out.println("\n"); /* ===================================================== Make a string using the byte array ===================================================== */ String s = new String(b); // Make a String s using byte array b System.out.println("String = " + s); System.out.println("ASCII codes (in decimal) for the string:"); for (int i = 0; i < s.length(); i++) { System.out.println( (int) s.charAt(i) ); // System.out.println(String.format("%x", (int) s.charAt(i) ); } } } }