You are viewing a single comment's thread. Return to all comments →
Easiest way to handle this task!!!!!!
import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern;
public class Solution{ public static void main(String[] args) { Scanner scan = new Scanner(System.in); String s = scan.nextLine(); scan.close();
String regex = "[a-zA-Z]+"; String countRegex = "[a-zA-Z]+"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(s); Pattern pattern1 = Pattern.compile(countRegex); Matcher matcher1 = pattern1.matcher(s); int tokens = 0; while (matcher1.find()) { tokens++; } System.out.println(tokens); while (matcher.find()) { System.out.println(matcher.group()); } }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Java String Tokens
You are viewing a single comment's thread. Return to all comments →
Easiest way to handle this task!!!!!!
import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern;
public class Solution{ public static void main(String[] args) { Scanner scan = new Scanner(System.in); String s = scan.nextLine(); scan.close();
}