Write a Java Program to Iterate through each characters of the string.

Write a Java Program to Iterate through each characters of the string.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
class Main {
  public static void main(String[] args) {

    // create a string
    String name = "Programiz";

    System.out.println("Characters in " + name + " are:");

    // loop through each element
    for(int i = 0; i<name.length(); i++) {

      // access each character
      char a = name.charAt(i);
      System.out.print(a + ", ");
    }
  }
}

Final output

Leave a Comment