第五周课程总结和实验报告

课程总结:学会了关于String类的常用方法,并且在做题过程中学会了很多的一些关于Stirng类的应用。

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

  • 统计该字符串中字母s出现的次数。
  • 统计该字符串中子串“is”出现的次数。
  • 统计该字符串中单词“is”出现的次数。
  • 实现该字符串的倒序输出。
package twst;
public class test {
 public static void main(String args[]) {
  String str="this is a test of java";
  int x=(str.split("s")).length-1;
  System.out.println("s出现的次数="+x);
  int n=(str.split("is")).length-1;
  System.out.println("is出现的次数="+n);
  char s='s',i='i';
  char c[]=str.toCharArray();
  int count=0;
  for(int j=0;j<c.length;j++) {
   if(' '==c[j] && i==c[j+1] && s==c[j+2] && ' '==c[j+3]) {
    count++;
   }
  }
  System.out.println("单词is出现的次数="+count);
  for(int a=c.length-1;a>=0;a--) {
   System.out.print(c[a]);
  }
 }
}

 

 2.请编写一个程序,使用下述算法加密或解密用户输入的英文字串。要求源代码、结果截图。

package twst;

public class jiami {
    public String jiami(String s1){ 
        int i,j; 
        String allstring="ABCDEFGABC"; 
        StringBuffer ss = new StringBuffer();
        for(j=0;j<s1.length();j++) { 
            char s2=s1.charAt(j);
            for(i=0;i<allstring.length()-3;i++){ 
                char allstring1=allstring.charAt(i); 
                char allstring2=allstring.charAt(i+3); 
                if(allstring1==s2) {
                    ss.append(allstring2);
                    break;
                }
            } 
        } 
        String s3 = ss.toString();
        return s3; 
    } 
} 


package twst;

public class password {
    public static void main(String[] args){ 
        jiami newpassword=new jiami(); 
        String str="ABCDEFH";
        System.out.print(newpassword.jiami(str)); 
    } 
}

 

 

 

 

 

问题:这道题不会写,我现在还是有点不会写。

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

package twst;

public class test {
    public static void main(String args[]) {
        String str="ddejidsEFALDFfnef2357 3ed";
        char c[]=str.toCharArray();
        for(int i=0;i<c.length;i++) {
            if(c[i]>='A'&&c[i]<='Z') {
                System.out.println("大写英文字母="+c[i]);
            }
            else if(c[i]>='a'&&c[i]<='z') {
                System.out.println("小写英文字母="+c[i]);
            }
            else {
                System.out.println("其他字符="+c[i]);
            }
        }
        
    }
}

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/shigedidi/p/11599818.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值