// // File: /home/cs255001/demo/atoi/ConvInt1Digit.java // // Converting a binary number between 0 and 9 to a String // public class ConvInt1Digit { public static void main(String[] args) throws Exception { int i; char[] c = new char[1]; // char array of size 1 // (because we only have 1 character) i = 10; // Change to any value between 0 and 9 // If you use i = 10, program will pring : // Can you figure out WHY ??? c[0] = (char) (i + 48); // c is equal to ASCII code for the number ! /* --------------------------------------------- Make a string out of the character(s) ---------------------------------------------- */ String s = new String(c); System.out.println(">>> " + s); /* --------------------------------------------- Prove to students that s is a string ---------------------------------------------- */ s = s + 10000; System.out.println(">>> " + s); } }