publicclassdemol2 { publicstaticvoidmain(String[] args) { System.out.println("找寻2到10000素数"); //定义计数器并初始化 byte count=0; for (inti=2; i < 10000; i++) { if(Find(i)){ System.out.print(i+"\t"); count++; if (count==8) { System.out.println(); count=0; } } } }
//检查一个数是不是素数 publicstaticbooleanFind(int a) { for (inti=2; i < a; i++) { if(a%i==0)returnfalse; } returntrue; } }
3:设有英文短文如下,统计输出以字母 w 开头的单词数; 统计输出单词中含“or”字符串的单词数; 统计输出长度为 3 的单词数。
Last fall I walked with a friend in hometown. He was recognized as the most stupid among my childhood playmates, but he has now been Number One in an enterprise.When we came to a fork, a blind man walked from another direction. Testing the road with his bamboo pole, the blind man was walking very slowly towards the road we were going to.I chatted with my friend as we were walking. I talked about my five job-hoppings within two years and the experiences I was still struggling in the plight now. My friend nodded and smiled, but he kept silent all along. After a while, I occasionally looked back and found the blind man had vanished.