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

    •统计该字符串中字母s出现的次数。

    public class test {
    	public static void main(String[] args) {
    		String s="this is a test of java";
    		int sum=0;
    		char[] a=s.toCharArray();
    		for(int i=0;i<a.length;i++) {
    			if(a[i]=='s')
    				sum++;
    		}
    		System.out.println(sum);
    	}
    
    
    }
    
    

    •统计该字符串中子串“is”出现的次数。

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

    •统计该字符串中单词“is”出现的次数。

    public class test {
    	public static void main(String[] args) {
    		String s="this is a test of java";
    		int sum=0;
    		String[] str=s.split(" ");
    		for(String e:str){
                if(e.equals("is")) {
                  sum++;
                }
    		    
    		   
    	    }
    		 System.out.println("单词is出现的次数="+sum);
    
    
    
    
         }
    }
    

    •实现该字符串的倒序输出。

    public class test {
    	public static void main(String[] args) {
    		String s="this is a test of java";
    		int sum=0;
    		char a[]=s.toCharArray();
    		System.out.print("倒叙输出为:");
    		for(int i=s.length()-1;i>=0;i--){
    			System.out.print(a[i]);
    		    
    		   
    	    }
    
    
    
    
    
         }
    }
    

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

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

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

    学习总结

    继承

    类的继承格式:

    class 子类 extends 父类{}
    
    

    目的就是通过子类扩展父类的功能
    在Java中,一个子类只有一个父类
    而且子类不能直接访问父类的私有成员,但可以调用非私有方法来间接访问私有操作
    子类在继承父类时会有一个隐藏的super()方法,可以调用父类中无参构造,所以最好在父类中加一个无参构造方法

    覆写

    覆写和重载
    书169

    权限大小:private<default<piblic,子类在覆写时,权限不能变小
    main方法中不能用this和super,而且this和super不能同时调用
    this和super的区别在书

  • 相关阅读:
    update inner join
    Centos 7安装docker
    使用Let's Encrypt搭建永久免费的HTTPS服务
    upstream timed out (10060: A connection attempt failed because the connected party did not properly respond
    MySQL死锁分析一例
    solr定时更新索引遇到的问题(SolrDataImportProperties Error loading DataImportScheduler properties java.lang.NullPointerException)
    Java中的关键字 transient
    Spring 4 使用Freemarker模板发送邮件&添加附件
    Spring 4 创建REST API
    Spring 4 异常处理
  • 原文地址:https://www.cnblogs.com/hy14157/p/11593041.html
Copyright © 2011-2022 走看看