• 第五周课程总结&试验报告


    this和super的区别

    区别点

    this

    super

    属性访问

    访问同类中的属性,如果本类没有此属性则从父类中继续查找

    访问父类中的属性

    方法

    访问本类中的方法,如果本类中没有此方法,则从父类中继续查找

    直接访问父类中的方法

    调用构造

    调用本类构造,必须放在构造方法的首行

    调用父类构造,必须放在子类构造方法的首行

    特殊

    表示当前对象

    无此概念

    注意:

    this和super都可以调用构造方法,但两者市不可以同时出现的,因为两者调用构造方法市都必须放在构造方法的首行。

    无论子类如何操作,最终必须要先调用父类中的构造方法。

    访问限制:子类是不能直接访问父类中的私有成员的,但是子类可以调用父类中的非私有方法。

    1.已知字符串:"this is a test of java".按要求执行以下操作:(要求源代码、结果截图。)

    • 统计该字符串中字母s出现的次数。
    • 统计该字符串中子串“is”出现的次数。
    • 统计该字符串中单词“is”出现的次数。
    • 实现该字符串的倒序输出。
    package test;
    
    public class work {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
    
            String str="This is a test of java";
            int count=0;
            char[] c=str.toCharArray();
            for(int i=0;i<c.length;i++) {
                if(c[i]=='s') {
                    count++;
                }
            }
            System.out.println(count);
        }
    
    }

    package test;
    
    public class work {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            String str = "this is a test of java";
            String s = "is";
            String[] arr = (","+str.toLowerCase()+",").split(s);
            System.out.println(arr.length - 1);
        }
    
    }

    package test;
    
    public class work {
        public static void main(String[] args) {
            String str = "this is a test of java";
            String atr[];
            int count=0;
            atr=str.split(" ");
            for(String c:atr){
                if(c.equals("is")){
                    count++;
                }
            }
            System.out.println(count);
        }
    }

    package test;
    
    public class work {
          public static void main(String[] args) {
                
              StringBuffer str = new StringBuffer("this is a test of java");
              System.out.println(str.reverse());
              }
          }

    package first;
    import java. util.*;
    public class test {
          public static void main(String[] args) {    
                      Scanner sc =new Scanner(System.in);
                      String str1 = sc.nextLine();
                      char c[] = str1.toCharArray();
                      char a[] = new char[str1.length()];
                      int i,j=0;
                      if(str1.length()==1) {
                          System.out.println(c);
                      }
                      else if(str1.length()==2) {
                          System.out.print(c[1]);
                          System.out.print(c[0]);
                      }
                      else {
                          for(i = c.length-3;i<c.length;i++) {
                              a[j] = c[i];
                              j++;
                          }
                          for(i=0;i<c.length-3;i++) {
                              a[j]=c[i];
                              j++;
                          }
                      }
                      System.out.println(a);
                  }
              }

    package first;
    import java. util.*;
    public class test {
        public static void main(String[] args) {
                    String str="ddejidsEFALDFfnef2357 3ed"; 
                    int d=0,x=0,f=0; 
                    char c[]=str.toCharArray(); 
                    for(char a:c){ 
                        if(a>='a'&&a<='z'){ 
                           d++; 
                        } 
                        else if(a>='A'&&a<='Z'){ 
                            x++; 
                        } 
                        else{ 
                            f++; 
                        } 
                    } 
                    System.out.println("小写英文字母数:"+x);
                    System.out.println("大写英文字母数:"+d);
                    System.out.println("非英文字母数:"+f);
                } 
            }

  • 相关阅读:
    再探最大公约数
    非旋treap
    初赛毒瘤汇总(持续更新中)
    架构漫谈阅读笔记五--以豆瓣得基础架构为例
    架构设计小论文
    第一阶段
    架构漫谈阅读笔记六--以淘宝数据魔方技术架构解析为例
    学习进度第八周
    架构漫谈阅读笔记一
    软件架构之 Refined Architecture阶段
  • 原文地址:https://www.cnblogs.com/shihao0701/p/11593576.html
Copyright © 2020-2023  润新知