Given a string S and Q query strings(q1,q2,...), check for each query string whether or not it is sub-sequence of S Here is my approach. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. 

import java.io.InputStreamReader;
import java.util.Scanner;

public class Query {

public static void main(String[] args) {

    Scanner scanner = new Scanner(new InputStreamReader(System.in));
    String str=scanner.next();
    int n=scanner.nextInt();
    while(n--&gt;0){
        String sub=scanner.next();
        if(isSub(str,sub))
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}

static boolean isSub(String str, String sub){
    int j=0;
    int x=str.length();
    int y=sub.length();
    for(int i=0;i&lt;x &amp;&amp; j&lt;y;i++){
        if(str.charAt(i)==sub.charAt(j)) j++;
    }
    return (j==y);
}
}


Please critique my code and also suggest me how to increase efficiency of this code.
Formatting

Everything inside your class body should be indented by one step further than it currently is.
Binary operators (+,-, ...) are usually surrounded by one space to make reading them easier

Outputting results
Your if-else statement can be easily replaced by a ternary statement because it IMO is too trivial to actually be worth the effort of reading 5 lines for it.
In other cases I'd advocate against using the ternary, but here it's just so crudely obvious I can't help but recommend using it.
Immutability
It's significantly cleaner to not allow changing your reference string after you read it in. Mark effectively final variables as final explicitly to ease reading.
After applying this handful of changes your code looks as follows:
public class Query {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(new InputStreamReader(System.in));
        final String str = scanner.next();
        int n = scanner.nextInt();
        while (n-- &gt; 0) {
            String sub = scanner.next();
            System.out.println(isSub(str,sub) ? &quot;Yes&quot; : &quot;No&quot;);
        }
    }
}