WAP to print first and last characters of string

import java.io.*;
class StringCharacters
{
public static void main(String args[])
{
String s1="0";
char a,b;
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the alphabets of string");
try
{
s1=bf.readLine();
}
catch(Exception e)
{
e.printStackTrace();
}
a=s1.charAt(0);
b=s1.charAt(s1.length()-1);
System.out.println("the first character of string is:"+a);
System.out.println("the last character of string is:"+b);
}
}

Comments