zoukankan      html  css  js  c++  java
  • 第五周总结

    已知字符串:"this is a test of java".按要求执行以下操作

    统计该字符串中字母s出现的次数。
    统计该字符串中子串“is”出现的次数。
    统计该字符串中单词“is”出现的次数。
    实现该字符串的倒序输出。

    public class daoxu {
    public static void main(String[] args) {
    String s = "this is a test of java";
    int x = (s.split("s")).length - 1;
    System.out.println("字符串中字母s出现的次数" + x);

    int y = (s.split("is")).length - 1;
    System.out.println("字符串中子串“is”出现的次数" + y);

    int z = (s.split(" is")).length - 1;
    System.out.println("字符串中单词“is”出现的次数" + z);

    StringBuffer str = new StringBuffer("this is a test of java");
    System.out.println(str.reverse()); }
    }

    2.请编写一个程序,使用下述算法加密或解密用户输入的英文字串

    import java. util.*;
    public class jiami{
    public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    System.out.println("请输入要加密的英文字串");
    String str = sc.nextLine();

    char n;
    String str1=new String();
    for(int i=0;i<str.length();i++) {
    n = str.charAt(i);
    n = (char)(n+3);

    str1+=n;
    }
    System.out.println("加密后的子串是: "+str1);
    }
    }

    3.已知字符串“ddejidsEFALDFfnef2357 3ed”。输出字符串里的大写字母数,小写英文字母数,非英文字母数。

    public class daxiao {
    public static void main(String[] args) {
    int x,y,z;
    x=y=z=0;
    String s = "ddejidsEFALDFfnef2357 3ed";
    char c[] = s.toCharArray();
    for(int i=0;i< c.length;i++) {
    if(c[i]>= 'a'&&c[i] <= 'z') {
    x++;
    }

    else if(c[i] >= 'A'&&c[i]<='Z') {
    y++;
    }

    else {
    z++;
    }
    }
    System.out.println("字符串里的大写英文字母数" +y);
    System.out.println("字符串里的小写英文字母数" +x);
    System.out.println("字符串里的非英文字母数" +z);
    }

    }

     

    学习总结

    1.本周我们学习了继承的基本概念:子类与父类。子类通过extends来继承父类。在子类中可以用super()来调用父类的构造方法。在继承的父类的方法中可以对方法进行覆写。
    2.super与this时一对冤家他们不能同时出现。在内容上也有很大不同。如super只能从父类中调用方法,而this实在子类没有时才调用父类。而且都要放在构造方法的首行。
    3.final关键字是父类挡住子类继承的一道屏障,它可以让定义的类不被继承,而且使变量变成常量。
    4.子类可以自动转化为父类,而父类要强制转化为子类。

  • 相关阅读:
    IO 单个文件的多线程拷贝
    day30 进程 同步 异步 阻塞 非阻塞 并发 并行 创建进程 守护进程 僵尸进程与孤儿进程 互斥锁
    day31 进程间通讯,线程
    d29天 上传电影练习 UDP使用 ScketServer模块
    d28 scoket套接字 struct模块
    d27网络编程
    d24 反射,元类
    d23 多态,oop中常用的内置函数 类中常用内置函数
    d22 封装 property装饰器 接口 抽象类 鸭子类型
    d21天 继承
  • 原文地址:https://www.cnblogs.com/slob/p/11600583.html
Copyright © 2011-2022 走看看