/*项目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.*/
public class Statistics {

public static void main(String[] args) {
        String s="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.";
        String[]strs=s.split(" "); // 第一次分割空格
        int startWithW=0;//字母 w开头的单词数
        int countor = 0; //统计单词数 
        int count3=0; //指定的单词统计 
        for (String str1:strs){
            if(str1.charAt(0)=='w')
            startWithW++;}
            System.out.println("一共有"+startWithW+"个w开头的单词");
        for (String str2:strs)    {
            if(str2.contains("or"))
                countor++;}
            System.out.println("一共有"+countor+"个含有or的单词");
            for (String str3:strs)    
            if(str3.length()==3){
                count3++;
            }
            System.out.println("一共有"+count3+"个长度为3的英文单词");
            
            
        }

}

用java实现字符串的部分应用相关推荐

  1. java从字符串中提取数字

    1.做一下操作时会一般会用到提取数字操纵: a.列表中有翻页,当新添加的数据不是放在第一条或者最后一条时,需要翻页并循环找到对应的那条数据 b.当新添加的数据放在第一条或者最后一条时,则不需要翻页,只 ...

  2. 判断字符串不包含某个字符php,java判断字符串是否包含某个字符的方法

    java判断字符串是否包含某个字符的方法: 一.contains方法 1:描述 java.lang.String.contains() 方法返回true,当且仅当此字符串包含指定的char值序列 2: ...

  3. java案例——字符串反转

    java案例--字符串反转 1.需求: 定义一个方法,实现字符串反转.键盘录入一个字符串,调用该方法后,在控制台输出结果 例如,键盘录入abc,输出结果cba 2.思路: 1.键盘录入一个字符串,用S ...

  4. Java案例——字符串拼接

    Java案例--字符串拼接案例 1.案例需求 定义一个方法,把int数组中的数据按照指定的格式拼接成一个字符串返回,调用该方法,并在控制台输出结果 例如,数字为int[] arr = {1,2,3}; ...

  5. java之字符串学习记录

    java之字符串学习记录 public class StringDemo { public static void main(String[] args) { //静态初始化字符串 String s1 ...

  6. JAVA关于字符串字符数组处理的小题目

    JAVA关于字符串&&字符数组的小题目 第二题:分析以下需求,并用代码实现 1.键盘录入一个大字符串,再录入一个小字符串 2.统计小字符串在大字符串中出现的次数 3.代码运行打印格式: ...

  7. Java:字符串类String的功能介绍

    在java中,字符串是一个比较常用的类,因为代码中基本上处理的很多数据都是字符串类型的,因此,掌握字符串类的具体用法显得很重要了. 它的主要功能有如下几种:获取.判断.转换.替换.切割.字串的获取.大 ...

  8. java 包含汉字,【转载】Java判断字符串中是不是包含汉字

    [转载]Java判断字符串中是否包含汉字 import java.util.regex.Matcher; import java.util.regex.Pattern; public class If ...

  9. jni和java之间字符串的转换

    jni和java之间字符串的转换方法. C的实现: JNIEXPORT jstring JNICALL Java_Android123_CwjC (JNIEnv *env, jobject obj, ...

  10. java 获取字符串长度_ava练习实例:java字符串长度与Java String charAt() 方法 (建议收藏)...

    JJava 字符串长度 public class StringDemo {public static void main(String args[]) {String palindrome = &qu ...

最新文章

  1. JSP Tomcat8.0运行连接池时发生异常【AbstractMethodError oracle.jdbc.driver.T4CConnection.isValid(I)Z】...
  2. 在Linux中安装R语言包,遇到无法验证下列签名的错误
  3. java水果超市mysql_Java基础 | 项目实战之水果超市
  4. Animation Framework
  5. python在自动化中的应用_python中在自动化运维的应用
  6. 【UML】概念、关联、画画(一)
  7. MessagePack 二进制序列化格式 开发入门详解
  8. H2O中的随机森林算法介绍及其项目实战(python实现)
  9. Python下time模块和datetime模块的使用
  10. 编译OpenCV缺少python27_d.lib的解决方法
  11. js根据本地文件路径上传文件(流上传)
  12. swing的几种布局
  13. 【Ubuntu】QT程序 could not find or load the Qt platform plugin “xcb“ in “报错解决
  14. matlab计算复活节概率,复活节是几月几日_计算复活节日期_我爱历史网
  15. 【更新1.0:PoC发布】CVE-2020-1350: Windows DNS Server蠕虫级远程代码执行漏洞通告
  16. 数画-AI绘画-免费的人工智能AI绘画网站
  17. 阿里云ID2物联网设备身份认证系统
  18. 华为往事(十五)--华为北京研究所
  19. VMware虚拟机配置环境变量及MySQL
  20. zk和quartz实现分布式定时调度

热门文章

  1. 微服务设计原则之AKF原则
  2. 学习HM微博项目第9天
  3. etag java_HTTP ETag和HTTP重定向
  4. 全网最全Spring面试题之高级篇整理总结(共25题,附超详细解答)
  5. Manacher(马拉车)算法—简略讲解
  6. 计算机会考在线考试系统,数苑_在线考试平台
  7. JavaC++题解与拓展——leetcode812.最大三角形面积【么的新知识】
  8. idea远程连接hive失败
  9. idea+maven+selenium环境搭建
  10. .isEmpty()使用示例