How to use the charAt() method to get the last character in a string 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";
            System.out.println(s.charAt(s.length() - 1));
            
            char ch = s.charAt(s.length() - 1);
            System.out.println(ch);

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

/*
           
run:
     
e
e
  
 */

 



answered Nov 21, 2016 by avibootz

Related questions

1 answer 154 views
1 answer 239 views
1 answer 309 views
309 views asked Feb 9, 2019 by avibootz
1 answer 120 views
...