题解 | BFS

BFS

https://www.nowcoder.com/practice/22da7730da5d4a129a188ba24d22f2bf

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next().toLowerCase();
        //法1:截取字符串
        // for(int i = 0; i < s.length(); i++){
        //     if(s.substring(i,i+3).equals("bob")){
        //         System.out.print(i);
        //         break;
        //     }
        // }
        //法2:indexof定位
        int index = s.indexOf("bob");
        System.out.print(index);
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务