首页 技术 正文
技术 2022年11月15日
0 收藏 533 点赞 2,170 浏览 1413 个字

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

统计该字符串中字母s出现的次数。

统计该字符串中子串“is”出现的次数。

统计该字符串中单词“is”出现的次数。

实现该字符串的倒序输出。

package test2;public class Test111 { String s = "this is a test of java";
static Test111 OneString = new Test111();
public static void main(String[] args) {
OneString.numberS();
OneString.numberIS();
OneString.numberwordIS();
OneString.reversal();
}
public void numberS() {
int number = 0;
for(int i = 0 ; i < s.length(); i++) {
char c = s.charAt(i);
if(c=='s') {
number++;
}
}
System.out.println("S出现次数"+number);
}
public void numberIS() {
int number = 0;
for(int i = 1 ; i < s.length() ; i++) {
char c = s.charAt(i-1);
char c1 = s.charAt(i);
if(c=='i'&&c1=='s') {
number++;
}
}
System.out.println("字符IS出现次数"+number);
}
public void numberwordIS() {
int number = 0;
String s[] = this.s.split(" ");
for(String s1 : s) {
if(s1.equalsIgnoreCase("is")) {
number++;
}
}
System.out.println("单词IS"+number);
}
public void reversal() {
StringBuilder word = new StringBuilder();
for(int i = s.length()-1 ; i>=0 ; i--) {
char c = s.charAt(i);
word = word.append(s.charAt(i));
}
System.out.println("倒序输出 " + word);
}
}

第二题我不会

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

package test2;
public class simple {
static String s = "ddejjdsEFALDFfnef2357 3ed";
public static void main(String[] args) {
int Word = 0;
int word = 0;
int other = 0;
for(int i = 0;i < s.length();i++) {
char c = s.charAt(i);
if(c>='A' && c<='Z') {
Word++;
}else
if(c>='a' &&c<='z') {
word++;
}else {
other++;
}
}
System.out.print("大写字母: "+Word+",小写字母 "+word+",其他 "+other);
}
}

学习总结

这周学了一些关于 String类的用法

学习了一些关于继承的知识以及对于子类调用父类的方法与构造方法的注意事项

还了解了抽象类的一些知识

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,104
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,580
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,428
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,835
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,918