1215课后练习----判断字符串位置

package com.hanqi;

public class Testco {
    public static void main(String[] args) 
    {
    String str1 = "字符串常量";
    
    //判断字符串str2是否是在字符串str1的最后位置
    
    String str2 = "";
    str1 = "abcdefghijklmnopqrstuvwxyz";
    str2 = "yz";
    
    int a = str1.length();
    
    System.out.println("a="+a);
    
    int b = str2.length();
    
    System.out.println("b="+b);
    
    int c = str1.indexOf(str2);
    
    System.out.println("c="+c);
    
    System.out.println("判断结果是"+(b==a-c));
    
    System.out.println("endsWith判断结果为"+str1.endsWith(str2));
}
}

运行结果为:

posted @ 2015-12-15 15:57  秦萧不再  阅读(151)  评论(0编辑  收藏  举报