import java.util.Scanner; /** Some more examples for String processing. */ public class StringProcess { /** Problem: Given a string with lots of words separated by spaces, * return the nth word in the string. */ public static void main(String[] args) { String doc="Four score and seven years ago"; // for loop n-1 times to find space before the nth word int pos=-1, n=6; for (int i=0;i