菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
16
0

第五周总结

原创
05/13 14:22
阅读数 58669

已知字符串:"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("加密后的子串是:\n"+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.子类可以自动转化为父类,而父类要强制转化为子类。

 

发表评论

0/200
16 点赞
0 评论
收藏