Java Reference
In-Depth Information
< Day Day Up >
Puzzle 18: String Cheese
This program creates a string from a sequence of bytes, then iterates over the characters in the string
and prints them as numbers. Describe the sequence of numbers that the program prints:
public class StringCheese {
public static void main(String args[]) {
byte bytes[] = new byte[256];
for(int i = 0; i < 256; i++)
bytes[i] = (byte)i;
String str = new String(bytes);
for(int i = 0, n = str.length(); i < n; i++)
System.out.print((int)str.charAt(i) + " ");
}
}
Solution 18: String Cheese
 
 
Search WWH ::




Custom Search