zoukankan      html  css  js  c++  java
  • 第五周课程总结和实验报告

    课程总结:学会了关于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]);
                }
            }
            
        }
    }

  • 相关阅读:
    OpenGL3:先导篇 数据类型
    Linux开发:同步与异步
    前端面试题
    工具
    API和DLL
    CSS了一个浮动导航条
    AJAX背景技术介绍
    2014年8月18日17:02:53
    怎么增加照片的KB大小
    HTML5增加的几个新的标签
  • 原文地址:https://www.cnblogs.com/shigedidi/p/11599818.html
Copyright © 2011-2022 走看看