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

    班级 计科二班 学号 20188425 姓名 IM
    完成时间2019/9/27
    评分等级
    实验三 String类的应用
    实验目的
    掌握类String类的使用;
    学会使用JDK帮助文档;
    实验内容
    1.已知字符串:"this is a test of java".按要求执行以下操作:(要求源代码、结果截图。)
    统计该字符串中字母s出现的次数。
    统计该字符串中子串“is”出现的次数。
    统计该字符串中单词“is”出现的次数。
    实现该字符串的倒序输出。

    实验代码 1):

    package 实验室;
    public class demo3 {
    	public static void main(String[] args) {
            String str="this is a test of java";
            int count=0;
            char c[]=str.toCharArray();
            for(int i=0;i<c.length;i++){
                if(c[i]=='s'){
                    count++;
                }           
             }
            System.out.println("s出现了"+count+"次");
                
        }
    }
    

    运行结果截图:

    实验代码 2):

    package 实验室;
    
    public class demo2 {
    	public static void main(String args[]) {
    		String str = "This is a test of java";
    		int count=0;
    		
    		String[] s=str.split(" ");
    		for(String e:s) {
    			if(e.equals("is")) {
    				count++;
    			}
    		}
    		System.out.println("is出现了"+count+"次");
    	}
    }
    

    运行结果截图:

    实验代码 3):

    package 实验室;
    
    public class demo1 {
    	public static void main(String args[]) {
    		String str="This is a test of java";
    		int count=str.indexOf("is");
    		System.out.println(count);
    	}
    
    }
    

    运行结果截图:

    实验代码 4):

    package 实验室;
    
    public class demo4 {
    	    public static void main(String args[]) {
    	        String str="This is a test of java";
    	        char s[] = str.toCharArray();
    	        for (int i=s.length-1;i>=0;i--) {
    	            System.out.print(s[i]);
    	        }
    	        
    	    }
    }
    

    运行结果截图:

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

    实验代码:

    package 实验室;
    
    import java. util.*;
    public class demo5 {
        public static void main(String[] args) {
            Scanner sc =new Scanner(System.in);
            String str1 = sc.nextLine();
            char c[] = str1.toCharArray();
            char a[] = new char[str1.length()];
            int i,j=0;
            if(str1.length()==1) {
                System.out.println(c);
            }
            else if(str1.length()==2) {
                System.out.print(c[1]);
                System.out.print(c[0]);
            }
            else {
                for(i = c.length-3;i<c.length;i++) {
                    a[j] = c[i];
                    j++;
                }
                for(i=0;i<c.length-3;i++) {
                    a[j]=c[i];
                    j++;
                }
            }
            System.out.println(a);
        }
    }
    

    代码出处:https://www.cnblogs.com/leisidiya/p/11580804.html

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

    package 实验室;
    
    public class demo6 {
    	    public static void main(String[] args) {
    	        String str="ddejidsEFALDFfnef2357 3ed";
    	        int x=0,y=0,z=0;
    	       char c[]=str.toCharArray();
    	       for(char e:c) {
    	    	   if(e>='a'&&e<='z'){ 
    	             x++; 
    	            } 
    	            else if(e>='A'&&e<='Z'){ 
    	              y++; 
    	            } 
    	            else{ 
    	                z++; 
    	            } 
    	        } 
    
    	        System.out.println("大写字母数:"+x);
    	        System.out.println("小写字母数:"+y);
    	        System.out.println("非英语字母数:"+z);
    	    }
    
    	}
    

    运行结果截图:

    学习总结:
    学到了什么:
    1、学习了继承的基本概念及用法:
    1)
    2)
    3)理解了父类和子类的关系:
    4)了解并掌握了隐含语句“super();”的用法:
    同时“super” 能调用父类的构造方法(非私有:private)、属性、方法等。
    5)学习了方法的重载和覆写:

    2、学习了多态:
    3、学习了类设计分析:

    学习不足之处:
    1、不能独立完成任务;
    2、对本周所学知识没有及时消化导致做题遇阻;
    3、不能举一反三(举一反一也有困难):运用同样的知识点不能做出两个甚至多个题型一样的编程题;
    4、写代码还是不够严谨,多次出现编译错误;

    学习需要改进的地方:(没有方向以至于上周上上周提出的改进之处都没有完全弄好)
    需要大佬指点。

    PS:课堂问题:运用继承性功能性输出小狗小猫的叫声,即输入“dog”,输出“wangwangwang”,输入“cat”,输出“miaomiaomiao”。
    实验代码:?????

  • 相关阅读:
    gvim e303 无法打开 “[未命名]“的交换文件,恢复将不可能
    AspectJ获取方法注解的信息
    type parameters of <T>T cannot be determined; no unique maximal instance exists for type variable T with upper bounds int,java.lang.Object
    MySQL@淘宝 资料分享
    MySQL的语句执行顺序
    关于HttpClient上传中文乱码的解决办法
    使用IntelliJ IDEA查看类的继承关系图形
    javax.net.ssl.SSLException: Certificate doesn't match any of the subject alternative names
    Failed to process import candidates for configuration class [com.simple.....]
    安装npm及cnpm(Windows)
  • 原文地址:https://www.cnblogs.com/ImportantMagic/p/11599992.html
Copyright © 2011-2022 走看看