Sunday 18 September 2016

String methods

12.12 Programs on String 

Programs on String methods 
1. public char charAt(int index)
  • This method returns the character at the specified index location.
-------------------------------------------------------------------
Program         :        charAt() method program
Program name  :        CharAtDemo1.java
Output             : 
                                a
                                b
                                c

class CharAtDemo1
{
public static void main(String args[])
{
        String s1 = "abcdefg";

        System.out.println(s1.charAt(0));
        System.out.println(s1.charAt(1));
        System.out.println(s1.charAt(2));
}
}

Compile          :          javac CharAtDemo1.java
Run                :          java CharAtDemo1
Output            :
                                 a
                                 b
                                 c
-------------------------------------------------------------------
Thanks for your time.
Nireekshan