Runtime Error: Runtime ErrorException in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0 at java.lang.String.charAt(String.java:658) at GFG.main(File.java:32)
import java.util.*;
import java.lang.*;
import java.io.*;
class GFG {
public static void main(String args[]) throws IOException
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-- > 0)
{
String str=sc.nextLine();
char c='\n';
int i;
for(i=0;i<str.length()-1;i++)
{
c=str.charAt(i);
if(c>=97&&c<=122)
{
if(i==0)
System.out.print((char)(c-32));
else if(i!=0&&str.charAt(i+1)==' '&&str.charAt(i-1)==' ')
System.out.print((char)(c-32));
else if(i!=0&&str.charAt(i+1)!=' '&&str.charAt(i-1)==' ')
System.out.print((char)(c-32));
else
System.out.print(c);
}
else
System.out.print(c);
}
c=str.charAt(i);
if(c>=97&&c<=122)
System.out.println((char)(c-32));
else
System.out.println(c);
}
}
}