• 2020.8.16收获


    学习内容

    1.文件名与类型的分离

    一个完整的文件名字包括文件名与类型的扩展名,例如,a.doc, b.txt, film.rbmv等,文件名与类型的扩展名之间用.分离。请使用string类型,编写一个程序实现文件名与类型扩展名的分离,例如,输入是字符串a.doc,输出是两个字符串a和doc。要求使用string类型实现。

    复制代码
    import java.util.Scanner;
    public class Study {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            System.out.print("请输入文件名:");
            String str = in.next();
            // 获得字符“.”出现的索引
            int p = str.indexOf(".");
            System.out.println("文件名:" + str.substring(0, p));
            System.out.println("类型扩展名:" + str.substring(p + 1));
        }
    }
    复制代码


     2.字符串查找判断

    输入两个字符串s1和s2,判断s1是否包含s2,给出结论,若包含,还需计算s1中s2的个数。要求使用string类型

    复制代码
    import java.util.Scanner;
    public class Study {
        public static void main(String[] args) {
            String str1, str2, str3;
            int m, n;
            int count = 0;
            Scanner in = new Scanner(System.in);
            System.out.print("请输入字符串s1:");
            str1 = in.nextLine();
            System.out.print("请输入字符串s2:");
            str2 = in.nextLine();
            // 判断字符串s1是否包含s2
            if ((str1.indexOf(str2)) != -1) {
                System.out.println("s1包含s2");
            } else {
                System.out.println("s1不包含s2");
            }
            m = str1.length();
            n = str2.length();
            // 判断s1中s2的个数
            for (int i = 0; i < m - n + 1; i++) {
                str3 = str1.substring(i, i + n);
                if (str3.equals(str2)) {
                    count++;
                }
            }
            System.out.println("包含个数为:" + count);
        }
    }
    复制代码

  • 相关阅读:
    pydoc (Development Tools) – Python 中文开发手册
    CSS :out-of-range 选择器
    wcschr (Strings) – C 中文开发手册
    gl (SGI IRIX) – Python 中文开发手册
    排版 | Typography (CSS) – Bootstrap 3 中文开发手册
    HTML 音频,视频 DOM ended 属性
    ASP.NET Web Forms 教程
    Linux 系统目录结构
    ADO Connection 对象
    JavaWeb 之 HttpServletRequest 类
  • 原文地址:https://www.cnblogs.com/ltw222/p/14151335.html
Copyright © 2020-2023  润新知