开发者

if statement not executing

开发者 https://www.devze.com 2023-04-11 08:07 出处:网络
for(int i=0;i<number.length();i++){ if(number.charAt(i)==0){ nums[i]=11; System.out.println(\"bob\");
for(int i=0;i<number.length();i++){
    if(number.charAt(i)==0){
      nums[i]=11;
      System.out.println("bob");
开发者_JS百科    }else{
    nums[i]=number.charAt(i);
  }
  }

I am trying to get all 0 values to equal 11 in the array of nums and print bob every time it does that but for some reason the first if statement doesnt seem to be executing even when charAt(i) equals 0. Could someone please explain what is wrong?


If this is a string don't you mean if (number.charAt(i) == '0') ?


You should ask:

if (number.charAt(i)=='0')

Because the number 0 is different from the character '0', and you're interested in the character.


try : if(number.charAt(i)=='0'). you compared int and char my mistake.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号