Saturday 15 June 2013

Use of java string function - endswith()

/*check end character or end string with this function*/
import java.io.*;

public class endswith
{
    public static void main(String []args)
    {
        String str;
        try
        {
            DataInputStream cin=new DataInputStream(System.in);
            System.out.println("Enter first String ");
            str=cin.readLine();
            if(str.endsWith('j'))
            {
                System.out.println(str+" is start with given character");
            }
            else
            {
                System.out.println(str+" is does not start with given character");
            }
        }
        catch(Exception e)
        {
            System.out.println(e);
        }
    }
}

No comments: