如 String k=AC 
   String l=AD
   String m=ABC
怎么实现 k与m 匹配  l与m不匹配
   

解决方案 »

  1.   

    个人觉得应该是包含的意思:class test{
    public static void main(String[] args){
      String k="AC";
      String l="AD";
      String m="ABC";
    if(m.contains(k))
     System.out.println("匹配");
    else if(m.contains(l))
     System.out.println("匹配");
    else
     System.out.println("不匹配");
    }
    }
      

  2.   


    package Test;public class MatchingChar {
    /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
     
      String k= "AC";  
      String l= "AD";
      String m= "ABC";
      
      play(m,k.charAt(0),k.charAt(k.length()-1));
      
      play(l,k.charAt(0),k.charAt(l.length()-1));
    }

    /**
     * 匹配字符
     * @param str 要匹配的字符串
     * @param firstChar 第一个字符
     * @param endChar 最后一个字符
     */ 
    public static void play(String str,char firstChar,char endChar){

    if(str.charAt(0) == firstChar && str.charAt(str.length() - 1) == endChar)
      System.out.println("匹配");
    else 
      System.out.println("不匹配");
    }}
      

  3.   

    LZ你什么意思?你的意思是K 与 M匹配   K = "AC"  M ="ABC"
    难道你想K的第一字符与M的第一字符切K的最后一个字符与M的最后一个字符匹配.
    拜托你说清楚 不然 不知如何?
      

  4.   

    我的想法,用hashmap吧。
    先把长度较长的字符串放到一个hashmap里。字符就是key,个数就是value
    比如aabc,那么
    <a,2>
    <b,1>
    <c,1>
    再看较短的字符串的字母存不存在那个hashmap。
    如果不存在,肯定不匹配。
    如果存在,将hashmap的value-1
      

  5.   


    public class Test
    {
    public static void main(String[] args)
    {
    String a = "abc";
    String b="ab";
    String c="ac";
    System.out.println(a.contains(b));   //true
    System.out.println(a.contains(c));   //false
    }
    }