⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 groups12.java

📁 JAVA编程思想第四版英文原版习题答案. pdf原版的
💻 JAVA
字号:
// strings/Groups12.java
// TIJ4 Chapter Strings, Exercise 12, page 536
/* Modify Groups.java to count all of the unique words that do not start with a 
* capital letter.
*/
import java.util.regex.*;
import static net.mindview.util.Print.*;
import java.util.*;

public class Groups12 {
	static public final String POEM =
	"Twas brillig, and the slithy toves\n" +
	"Did gyre and gimble in the wabe.\n" +
	"All mimsy were the borogoves,\n" +
	"And the mome raths outgrabe.\n\n" +
	"Beware the Jabberwock, my son,\n" +
	"The jaws that bite, the claws that catch,\n" +
	"Beware the Jubjub bird, and shun\n" +
	"The frumious Bandersnatch.";
	public static void main(String[] args) {
		Matcher m = Pattern.compile("(^[a-z]|\\s+[a-z])\\w+").matcher(POEM);
		Set<String> words = new TreeSet<String>();
		while(m.find()) {
			words.add(m.group());
		}
		print("Number of unique non-cap words = " + words.size());
		print(words);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -