Friday, 14 June 2013

program in java for string function indexOf()


import java.io.*;
class simple_index_of_type1
{
    public static void main(String args[])
    {
        String str;
        int pos;
        try
        {
            DataInputStream cin=new DataInputStream(System.in);
            System.out.println("Enter any string ");
            str=cin.readLine();
            pos=str.indexOf('a');
            System.out.println("The entered string is = "+str);
            System.out.println("The possition of that character is = "+pos);
        }
        catch(Exception e)
        {
            System.out.println("wrong data");
        }
    }
}

No comments: