第五周作业及总结

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

第一题代码

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);
    }
}

截图
1580496-20190927165707641-1686505426.png

第二题代码

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);
         }

          
    }

截图
1580496-20190927165821987-1931206321.png

第三题代码

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))
        }
    }

截图
1580496-20190927170922621-762349632.png

第四题代码

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);
}

   }

截图
1580496-20190927171356061-2031445323.png

第五题代码

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));
        }
    }

}

截图
1580496-20190927172106630-1868929787.png

第六题代码

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);
        
    }

}

截图
1580496-20190927172206487-692920545.png

总结:

1580496-20190927172739771-928165703.jpg

1580496-20190927172754678-625769061.jpg

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

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

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

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

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

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

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

转载于:https://www.cnblogs.com/ydlBLOG/p/11599167.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值