class ReplaceChar
{
static String replaceCharAt(String s, char c, int index)
{
int strLength = s.length();
if(index >= 0 && index<strLength)
{
char [] cArray = s.toCharArray();
cArray[index] = c;
return new String(cArray);
}
return null;
}
public static void main(String [] args)
{
String str = "Hello world";
char c = 'a';
int index = 1;
System.out.println(ReplaceChar.replaceCharAt(str, c, index));
index = 15;
System.out.println(ReplaceChar.replaceCharAt(str, c, index));
}
}