• 第五周课程总结&试验报告(三)


    第五周课程总结&试验报告(三)

    一.已知字符串:"this is a test of java".按要求执行以下操作:(要求源代码、结果截图。)

    统计该字符串中字母s出现的次数。
    统计该字符串中子串“is”出现的次数。
    统计该字符串中单词“is”出现的次数。
    实现该字符串的倒序输出。

    1.代码

    package text;
    
    public class text1 {
          public static void main(String[] args){
        	  String str = "this is a test of java";
        	  int count=0,n=0,a=0;
        	  
        	  int i=0;
        	  while(str.indexOf("is",i)!=-1){
        		  count++;
        		  i=str.indexOf("is",i)+1;
        	  }
        	  
        	  int j=0;
        	  while(str.indexOf("s",j)!=-1){
        		  n++;
        		  j=str.indexOf("s",j)+1;
        	  }  
        	  
        	  int b=0;
        	  while(str.indexOf(" is ",b)!=-1){
        		  a++;
        		  b=str.indexOf(" is ",b)+1;
        	  } 
        	  StringBuffer st = new StringBuffer(str);
        	  System.out.println("s的个数:"+n);
        	  System.out.println("字符is的个数:"+count); 
        	  System.out.println("单词is的个数:"+a);
        	  System.out.println("倒序:"+st.reverse().toString());
    }
        }
    

    2.运行

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

    1.代码

    package text;
    
    import java.util.*;
    public class test2 {
    
    	  public static void main(String[] args) {
    	      System.out.println("请输入一个字符串:");
    	      Scanner sc = new Scanner(System.in);
    	      String str = sc.nextLine();
    	      char s[] = str.toCharArray();
    	      char asc=0;
    	      for(int i=0;i<s.length;i++) {
    	          asc=(char)(s[i]+3);
    	          System.out.print(asc);
    	      }
    	  }
    } 
    

    2.运行

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

    1.代码

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

    2.运行

    总结:
    继承: 使用extends关键字可以实现继承的关系
    子类不能直接访问父类中的私有操作,要通过其他操作间接访问。
    访问权限 private < default < public
    重载发生在一个类中,覆写发生在继承中。

  • 相关阅读:
    A1151 LCA in a Binary Tree (30分)
    A1150 Travelling Salesman Problem (25分)
    A1069 The Black Hole of Numbers (20分)
    A1149 Dangerous Goods Packaging (25分)
    A1148 Werewolf
    A1147 Heaps (30分)
    Ubuntu下git,gitlab团队协作
    如何查看JDK_API 2019.2.23
    linux_day1 (腾老师)2019年3月25日18:11:43(CentOs)
    jpa_缓存
  • 原文地址:https://www.cnblogs.com/zh2250881784/p/11599545.html
Copyright © 2020-2023  润新知