5.9-2比较str1和str2截取后的子串

时间:2024-04-22 23:41:26
 package zfc;

 public class ZfcShcq {

     public static void main(String[] args) {
// TODO Auto-generated method stub String str1 = "Hello World !";//创建两个字符串
String str2 = "Oracle Java"; String s1 = str1.substring(7,9);//分别截取子串
String s2 = str2.substring(0,2); // System.out.println(s1);//用于调试,查看子串
// System.out.println(s2); if(s1.equalsIgnoreCase(s2))//比较子串,不区分大小写
{
System.out.println("两个子串相同");
}
else
{
System.out.println("两个子串并不相同");
} } }