package com.hanqi; import java.util.*; public class panduanzifuchuankaitoujiewei { public static void main(String[] args) { // TODO 自动生成的方法存根 System.out.print("请输入字符:"); Scanner str = new Scanner(System.in); String a = str.next(); String b = "abcdefghijklmn"; if (a.length() >= b.length()) { System.out.println("输入的字符长度有误"); } else { if (b.indexOf(a) == 0) { System.out.println("输入的字符是字符串的开头"); } else { System.out.println("输入的字符不是字符串的开头"); } if (a.equals(b.substring(b.length() - a.length()))) { System.out.println("输入的字符是字符串的结尾"); } else { System.out.println("输入的字符不是字符串的结尾"); } } } }