JAVA program for StringBuffer method charAt()

JAVA program for StringBuffer method charAt()

This JAVA program is to find the character at the specified index using StringBuffer method charAt().

StringBuffer method charAt() returns the character at the index passed to this method in the brackets.

Program

import java.util.*;

class sb3
{
	public static void main(String args[])
	{
		String str;
		Scanner sc = new Scanner(System.in);
		System.out.println("Enter the string");
		str = sc.nextLine();

		StringBuffer s = new StringBuffer(str);
		
		System.out.println("Character at index(3) = "+s.charAt(3));
	}
}

Output

Share Me!