Hello, in this case:
//Here null indicates no value (blank)
and letter 't' will be added in that blank space
System.out.print( replaceFirst(null,'t'));
System.out.print("\n");
The code should return null without doing anything else isn't it?
If you need to return a blank space plus the 'c' character value, you would add this lines in your function:
public static String replaceFirst(String Str,char c)
{
if(Str == null)
return new String("")+c;
else if(Str == "")
return ""+c;
else
{
Str = Str.substring(0,0) + c + Str.substring(0 + 1);
return Str;
}
}
Yoy can avoid to test the
char c parameter but it could contain some wrong values, if not properly initiated.