【发布时间】:2023-03-19 06:40:02
【问题描述】:
http://codingbat.com/prob/p126880
给定两个字符串,如果其中一个字符串出现在另一个字符串的最末尾,则返回 true,忽略大小写差异(换句话说,计算不应“区分大小写”)。注意: str.toLowerCase() 返回字符串的小写版本。
当它为真时我无法得到,它总是给出假。
public boolean endOther(String a, String b)
{
//variables
a.toLowerCase();
b.toLowerCase();
String f1="";
String f2="";
int d=0;
int sum=0;
//Program code;
if(a.length()-b.length()>0)
{
(f1).equals(a);
(f2).equals(b);
d=a.length();
}
else if(a.length()-b.length()<0)
{
(f1).equals(b);
(f2).equals(a); //gett**ing bigger and lower String**
d=b.length();
}
else if((a).equals(b))
sum++;
// I think problem is because it is not enter the for.
for(int i=0; i>d; i++)
{
if((f1.substring(i,i+f2.length())).equals(f2))
sum++;
}
if(sum>0)
return true;
else
return false;
}
【问题讨论】:
-
你希望
(f1).equals(a)做什么? -
我想让f1等于a
-
如果你想让f1等于a,你应该写
f1=a; -
a.toLowerCase();String 是最终的!您必须将 this 的值影响到变量