举例来说:char buf[] = {'a','b','c','d','e','f','\0','x','y','z'}当输入N=10或20,期待输出是6;当输入N=3或5,期待输出是3或5.

 

package JingDian;

public class diguichar {
    public static void main(String[] args){
        String[] buf = {"a","b","c","d","e","f","\0","x","y","z"};
        mystrlen k = new mystrlen();
        System.out.println(k.strlen(buf, 2));
        
    }
}

class mystrlen{
    public int strlen(String[] buf,int N){ 
        for(int i=0;i<buf.length;i++){
        if(buf[0]=="\0"||N==0)
            return 0;
        else if(N==1)
            return 1;
          else if(buf[i]=="\0"&&N>=i)
              return i;
          
        }
        return  N;
        
    }
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-27
  • 2021-12-17
  • 2022-12-23
  • 2021-11-15
  • 2021-09-04
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案