用自己的算法实现startsWith和endsWith功能

 1 package hanqi;
 2 
 3 import java.util.Random;
 4 import java.util.Scanner;
 5 
 6 public class zuoye {
 7 
 8     public static void main(String[] args) {
 9     
10         System.out.println("请输入一个字符串");
11         Scanner sc =new Scanner(System.in);
12         String str1 = new String();
13         str1=sc.nextLine();                                    //输入一个字符串,用来判断使用
14         
15         char kaitou;
16         kaitou=str1.charAt(0);                            //定义 kaitou 为刚才字符串的开头字母
17         
18         System.out.println("请输入一个字符判断是否为字符串的开头");
19         Scanner a1 =new Scanner(System.in);
20         String str2 = new String();
21         str2=a1.nextLine();
22         char kaitou1;
23         kaitou1=str2.charAt(0);
24         
25         if(kaitou==kaitou1)
26         {
27             System.out.println("输入的是开头");
28         }    
29         else
30         {
31             System.out.println("输入的不是字符串的开头");
32         }
33         
34         
35 
36     }
37 
38 }

原文地址:https://www.cnblogs.com/zs6666/p/5879005.html