The code is to shorten names.
When am executing in Hackerrank there is NullPointerException on temp.length() , temp.toUpperCase() , temp.substring(). Visit the question here
The First Line contains an integer N, which denotes the number of testcases.
Sample Input
3
Mohandas Karamchand Gandhi
Mervin R Sundharam
Muthu
Sample Output
M K Gandhi
M R Sundharam
Muthu
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) throws IOException {
Scanner sc= new Scanner(System.in);
int size= sc.nextInt();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String ar[] =new String[size];
for (int i= 0; i < size; i++) {
ar[i]=br.readLine();
}
for(int i= 0;i<size;i++){
String temp=" ";
temp=ar[i];
int pos=0;
for (int j= 0; j < temp.length(); j++)
if(temp.charAt(j)==' '){
System.out.print(temp.toUpperCase().charAt(pos)+ " ");
pos=j+1;
}
}
System.out.println(temp.toUpperCase().charAt(pos)+temp.substring(pos+1));
}
}
}