import java.util.*;
public class s22 {
public static void main(String[] args) {
//Your Code Here
Scanner sb=new Scanner(System.in);
int n=sb.nextInt();
int i,j;
String[] st=new String[1000];
String[] s=new String[n];
for(i=0;i<n;i++)
{
st[i]=sb.next();
}
for(j=0;j<n;j++)
{
String[] m=st[i].split(" ");
s[i]=m[m.length-1];
}
for(i=0;i<n;i++){
System.out.println(s[i]);}
}
}
I tried this code but shows null pointer exception after entering first value. For example if I give input as:
john is sleeping,
lisa rapper,
beautiful flower,
The output should be like:
sleeping,
rapper,
flower