+ 1
how can i print the second "FOR" or first "FOR" from the following wholeString using some loop not the substring method.
public class test{ public static void main(String[] args){ String wholeString ="ASK NOT WHAT YOUR COUNTRY CAN DO FOR YOU BUT WHAT YOU CAN DO FOR YOUR COUNTRY"; String[] justWords = wholeString.split(" ");String searchString ="FOR"; for(int i =0; i < justWords.length; i++){if(justWords[i].equals(searchString)){ System.out.println("The word "+ searchString +" is in the position: "+ i); } } } }
2 ответов
+ 9
Looks like u already have it figured, what do u want?
0
it prints both of the position if there is any duplicate words like "for" is there.I only want the particular ones position.
like print the first "for " position from the sentence