第五周课程总结与报告

浅浅的花香味﹌ 2023-06-02 10:58 72阅读 0赞

实验三 String类的应用
•实验目的
•掌握类String类的使用;
•学会使用JDK帮助文档;
•实验内容

1.已知字符串:”this is a test of java”.按要求执行以下操作:(要求源代码、结果截图。)
•统计该字符串中字母s出现的次数。
•统计该字符串中子串“is”出现的次数。
•统计该字符串中单词“is”出现的次数。
•实现该字符串的倒序输出。

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

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

一.实验代码

  1. package Fuck;
  2. public class Fuck {
  3. public static void main(String[] args) {
  4. // TODO Auto-generated method stub
  5. String s = "this is a test of java";
  6. int n = (s.split("s")).length - 1;
  7. System.out.println("s出现的次数" + n);
  8. int t = (s.split("is")).length - 1;
  9. System.out.println("is出现的次数" + t);
  10. int g = (s.split(" is ")).length - 1;
  11. System.out.println(" is 出现的次数" + g);
  12. StringBuffer str = new StringBuffer(s);
  13. str = str.reverse();
  14. System.out.println(str);
  15. }
  16. }

(1)实验结果
1580769-20190927200421226-217536775.png

二.实验代码

  1. public class RNG {
  2. public static void main(String[] args) {
  3. // TODO Auto-generated method stub
  4. System.out.println(" 加密还是解密 ?");
  5. Scanner input=new Scanner(System.in);
  6. int x;
  7. if(input.nextLine().equals("解密")){
  8. x=0;
  9. }
  10. else {
  11. x=1;
  12. }
  13. String s=input.nextLine();
  14. char[] ch=s.toCharArray();
  15. if(x==1) {
  16. for(int i=0;i<ch.length;i++){
  17. ch[i]=(char)(ch[i]+3);
  18. }
  19. }else {
  20. for(int i=0;i<ch.length;i++){
  21. ch[i]=(char)(ch[i]-3);
  22. }
  23. }
  24. s=s.valueOf(ch);
  25. System.out.println(s);
  26. }
  27. }

运行截图
1580769-20190927201206626-1140059528.png

三,实验代码

  1. public class FUCK1 {
  2. public static void main(String[] args) {
  3. // TODO Auto-generated method stub
  4. public static void main(String[] args) {
  5. // TODO Auto-generated method stub
  6. String s="ddejidsEFALDFfnef2357 3ed";
  7. char[]ch=s.toCharArray();
  8. int sd=0,sx=0,sf=0;
  9. for(int i=0;i<ch.length;i++) {
  10. if(ch[i]>='A'&&ch[i]<='Z') {
  11. sd++;
  12. }
  13. else if(ch[i]>='a'&&ch[i]<='z'){
  14. sx++;
  15. }
  16. else {
  17. sf++;
  18. }
  19. }
  20. System.out.println(sd);
  21. System.out.println(sx);
  22. System.out.println(sf);
  23. }
  24. }

运行截图
1580769-20190927201722934-1753599645.png

总结:
好嗨哦,感觉人生已经到达了高潮,感觉人生已经到达了巅峰。

转载于:https://www.cnblogs.com/dxl1314520/p/11600152.html

发表评论

表情:
评论列表 (有 0 条评论,72人围观)

还没有评论,来说两句吧...

相关阅读