Added after user name filed one extra hidden div with one more password field without name and value
Month: April 2016
How to get number of occurrence given word in a sentence in java
Code Example 1:
import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class NoOfOccurenceGivenWord { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scan = new Scanner(System.in); System.out.println("Enter a sentence :"); String sentence = scan.nextLine(); int i=0; System.out.println("Enter a keyword for finding number of occrence :"); String keyword = scan.nextLine(); Pattern p = Pattern.compile(keyword); Matcher m = p.matcher(sentence); while(m.find()){ i++; } System.out.println("total word count ="+i); } }