• 第五周作业及总结


    实验三 String类的应用
    实验目的
    掌握类String类的使用;
    学会使用JDK帮助文档;
    实验内容
    1.已知字符串:"this is a test of java".按要求执行以下操作:(要求源代码、结果截图。)
    统计该字符串中字母s出现的次数。
    统计该字符串中子串“is”出现的次数。
    统计该字符串中单词“is”出现的次数。
    实现该字符串的倒序输出。
    2.请编写一个程序,使用下述算法加密或解密用户输入的英文字串。要求源代码、结果截图。

    第一题代码

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

    截图

    第二题代码

    package 作业;
    
    public class zuoye2 {
    	  public static void main(String args[]) { 
    	      String str="this is  a test of java";
    	      int count=0;
    	      char s[];
    	      s=str.toCharArray();
    	      
    	      for (int i=0;i<s.length;i++) {
    	      if('i'==str.charAt(i)&&'s'==str.charAt(i+1)) {
    	    	  count++;
    	            }   
    	      }
    	      System.out.println("字符串is的次数:"+count);
    	     }
    
    	      
    	}
    

    截图

    第三题代码

    package 作业;
    public class zuoye3 {
        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")) {
        			 
        		 }
        		  System.out.println("单词is的次数:"+count))
        	}
        }
    

    截图

    第四题代码

    package 作业;
    
    public class zuoye4 {
    	public static void main(String args[]) {
    
    	   StringBuffer str =new   StringBuffer();
    	   
    	   str.append("this is a test of java");
    	   
    	   str.reverse().toString();
    	   
    	   System.out.println(str);
    }
    
       }
    

    截图

    第五题代码

    package 作业;
    import java.util.Scanner;
    public class zuoye5 {
    	public static void main(String args[]) {
    		System.out.println("加密前的字符串:");
    		
    		Scanner sc=new Scanner(System.in);
    		String sstr=sc.nextLine();
    		char[] a= str.toCharArray();
    		
    		System.out.println("加密后的字符串:");
    		for(char x:a) {
    			
    			System.out.print((char) (x+3));
    		}
    	}
    
    }
    

    截图

    第六题代码

    package 作业;
    public class zuoye6 {
        
        public static void main (String[] args){
            String str="ddejidsEFALDFfnef2357 3ed";
            
            char[] a=str.toCharArray();
            int x=0,y=0,z=0;
            for(int i=0;i<a.length;i++){
                if(a[i]>='A'&&a[i]<='Z'){
                    x++;
                }
                else if(a[i]>='a'&&a[i]<='z'){
                    y++;
                }
                else {
                    z++;
                }
            }
            System.out.println("大写字母数:"+x);
            System.out.println("小写字母数:"+y);
            System.out.println("其他符号数:"+z);
            
        }
    
    }
    

    截图

    总结:

    final:1.final声明的子类不能有子类

    2.final声明的方法不能被子类覆写

    3.final声明的变量既成为变量,常量不可以修改。

    抽象类的定义: 1.包含一个抽象方法的必须是抽象类

    2.抽象类和抽象方法必须使用abstract关键字声明

    3.抽象方法只需声明而不需要实现

    4.抽象类必须被子类继承,子类必须覆写抽象类的全部抽象方法。

  • 相关阅读:
    学习进度总结表
    关于软件工程的问题
    自我介绍
    web安全
    spring profile
    spring 装配
    python Descriptor (描述符)
    python string intern
    Java 对象内存占用
    java jdb命令详解
  • 原文地址:https://www.cnblogs.com/ydlBLOG/p/11599167.html
Copyright © 2020-2023  润新知