// CharactersInString.java
// Displays Unicode values of
// characters in command-line argument.
public class CharactersInString {
public static void main(String[] args)
{
String text = "ABC-XYZ abcd 0123";
System.out.println("Below are characters in this string: "
+ text);
System.out.println();
System.out.println();
System.out.println("Position Character Unicode");
System.out.println("-------- --------- -------");
System.out.println();
for ( int i = 0; i < text.length(); i++ )
{
// Display character's position in String text:
String positionText = Integer.toString(i);
for ( int j = positionText.length(); j < 2; j++ )
positionText = " " + positionText;
System.out.print(" " + positionText);
// Display the character itself:
char x = text.charAt(i);
System.out.print(" " + x + " ");
// Display the character's Unicode value
String valueText = Integer.toString(x);
for ( int j = valueText.length(); j < 4; j++ )
valueText = " " + valueText;
System.out.println(valueText);
} // for i
} // method main
} // class CharactersInString