Friday 14 June 2013

java program for string function charAt()

import java.io.*;
class simple_charAt_pos_type2
{
    public static void main(String args[])
    {
        String str;
        int pos;
        char s;
        try
        {
            DataInputStream cin=new DataInputStream(System.in);
            System.out.println("Enter any String ");
            str=cin.readLine();
            System.out.println("Your entered string is = \n"+str);
            System.out.println("Enter the possition which character you want sir");
            pos=Integer.parseInt(cin.readLine());
            s=str.charAt(pos);
            System.out.println("Character of that possition is = "+s);
        }
        catch(Exception e)
        {
            System.out.println("wrong data");
        }
    }
}

No comments: