xxxxxxxxxx
public class CharacterCount {
public static void main(String[] args) {
String str = "Hello, world!";
int count = 0;
// Iterate through each character until null character is encountered
for (int i = 0; str.charAt(i) != '\0'; i++) {
count++;
System.out.println("Character at position " + i + ": " + str.charAt(i));
}
System.out.println("Number of characters: " + count);
}
}