public String CheckChargeRule(String code)
{
String checkCR = null;
BusinessDao bd = new BusinessDao();
String[] getCR = bd.getChargeRule();
for(int i = 0;i<getCR.length;i++)
{
if(getCR[i] == code)
{
checkCR = "checked";
break;
}
}
return checkCR;
}
checkCR返回的值只是null,请问能让他返回checked吗?有实现的方法吗?谢谢!
{
String checkCR = null;
BusinessDao bd = new BusinessDao();
String[] getCR = bd.getChargeRule();
for(int i = 0;i<getCR.length;i++)
{
if(getCR[i] == code)
{
checkCR = "checked";
break;
}
}
return checkCR;
}
checkCR返回的值只是null,请问能让他返回checked吗?有实现的方法吗?谢谢!
顺便说一下,String[]不是字符数组,字符数组是char[]
package bao;public class Question1 {
String a[]={"1","2","3"};
void string(String s){
for(int i=0;i<3;i++){
if(a[i]==s) System.out.printf("ok!\n");
else System.out.printf("error!!!\n");
}
}
public static void main(String args[]) {
Question1 c=new Question1();
c.string("1"); }};
一、是你的IF(getCR[i] == code)这个表达式里的值不存在相等的情况 二、如果你确定getCR[i]和code有相等的什值,而没有能执行IF括号中的语句
那么你在IF表达式中用equals()方法来判断两个值是否相等
因为在判断两个字符串是否相等时,如果用==来比较,比较的是引用对像的引用址是 否想同,而不是引用对像指向的值是否想同.
string[] getcr=new string[?]
string一开始是要初始化的吧?
public String getChargeRule(){
String b[]={"1","2","3"};
return b[0];
}
}
public String CheckChargeRule(String code)
{
String checkCR = null;
BusinessDao bd = new BusinessDao();
String[] getCR =new String[1];
getCR[1]=bd.getChargeRule();
for(int i = 0;i<getCR.length;i++)
{
if(getCR[i] == code)
{
checkCR = "checked";
break;
}
}
return checkCR;
}
public static void main(String args[])
{
Test a=new Test();
System.out.println("resault"+a.CheckChargeRule("1"));
}
}改了下。~呵呵,大概那意思。