How to loop through all characters in a string using charAt() in Java

1 Answer

0 votes
package javaapplication1;

import java.io.IOException;

public class JavaApplication1 {

    public static void main(String[] args) throws IOException {

        try {

            String s = "Java Code";

            for (int i = 0; i < s.length(); i++) {
                char ch = s.charAt(i);
                System.out.println(ch);
            }

        } catch (Exception e) {
            System.out.print(e.toString());
        }
    }
}

/*
           
run:
     
J
a
v
a
 
C
o
d
e
  
 */

 



answered Nov 21, 2016 by avibootz

Related questions

1 answer 146 views
1 answer 154 views
3 answers 207 views
207 views asked Apr 8, 2021 by avibootz
4 answers 259 views
259 views asked Apr 4, 2021 by avibootz
1 answer 225 views
...