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

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

    package 题目一;
    
    public class 题目一 {
    	public static void main(String[] args) {
            int count=0;
            String str="this is test a java";
             for(int i=0;i<str.length();i++) {
                 if(str.substring(i,(i+1)).indexOf("s") != -1)
                     count++;
             }
                System.out.println(count);
            
        }
    }
    

    package 题目二;
    
    public class 题目二 {
    	public static void main(String[] args) {
            int count=0;
            String str="this is test a java";
             for(int i=0;i<str.length();i++) {
                 if('i'==str.charAt(i)&&'s'==str.charAt(i+1)) {
                   count++;
                 }
             }
                System.out.println("字符is出现的次数为:"+count);
            
        }
    }
    

    package 题目三;
    
    public class 题目三 {
    	public static void main(String[] args) {
            int count=0;
            int a=0;
            String str="this is test a java";
             for(int i=0;i<str.length();i++) {
                 if('i'==str.charAt(i)&&'s'==str.charAt(i+1)&&' '==str.charAt(i-1)) {
                   count++;
                 }
             }
                System.out.println("单词is出现的次数为:"+count);
            
        }
    }
    

    package 题目四;
    
    public class 题目四 {
    	public static void main(String[] args) {
            String str="this is test a java";
            StringBuffer buffer = new StringBuffer(str);
            System.out.println(buffer.reverse());
            
        }
    }
    

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

    package 加密3;
    import java.util.Scanner;
    public class 加密3 {
    	static void change() {  
            System.out.println("请输入字符串:");
            Scanner in = new Scanner(System.in);
            String str = in.nextLine();
            char c[]= str.toCharArray();//实现数据的输入并将其转换为数组
            char b[] = new char[50] ;//定义一个新的数组
            int j=0;
            for(int i = c.length-3;i<c.length;i++) {
                b[j]=c[i];
                j++;
            }
            for(int z=0;z<c.length-3;z++) {
                b[j]=c[z];
                j++;
            }//实现密码的移位
               System.out.println("加密后的密码为");
               System.out.println(b);
        }
        public static void main(String args[]) {
            change();
    
        }
    }
    
    

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

    package 字符串;
    import java.util.Scanner;
    public class 字符串 {
    	public static void main(String[] args) {
            int a=0,b=0,d=0;
            System.out.println("请输入字符串:");
            Scanner in = new Scanner(System.in);
            String str = in.nextLine();
            char c[]= str.toCharArray();
            for(int i=0;i<c.length;i++) {
                if(c[i]>='a'&&c[i]<='z') {
                    a++;
                }
                else if(c[i]>='A'&&c[i]<='Z') {
                    b++;
                }
                else
                    d++;
            }
            System.out.println("大写字母的个数为:"+b);
            System.out.println("小写字母的个数为:"+a);
            System.out.println("其它字符个数为:"+d);
        }
    }
    

    第五周学习总结:
    1.本周主要围绕string进行学习,首先就是实例化string类对象,
    2.其次就是string对象内容的比较,string类两种对象实例化方式的区别,详细的强调了字符串内容不可改变(一旦声明,不可改变),
    3.详细介绍了string类的常用方法。
    4.自己也总结到在string中比较内容使用equals方法,而“==”比较的只是两个字符串的地址值,
    5.保持热情,撸起袖子加油干!!!

  • 相关阅读:
    读取XML字符串到临时表
    Golang学习笔记
    Golang环境配置Centos
    IntelliJ Idea 常用快捷键列表
    Elasticsearch的Groovy Script自定义评分检索
    MSSQL读取xml字符串到临时表
    通过反射给对象属性动态赋值总结(含可空属性)
    。。。。。
    指定位置输出函数
    DBhelper
  • 原文地址:https://www.cnblogs.com/huanglexing/p/11599072.html
Copyright © 2011-2022 走看看