结构推理 设定5个字符串,要求只打印那些以字母“b”开头的串,编写程序完成。
【正确答案】public class prin_b { public static void main(String args[]) { String s1="hello"; String s2="bee"; String s3="java"; String s4="brove"; String s5="bag"; if(s1.indexOf('b')= =0) System.out.println(s1); if(s2.indexOf('b')= =0) System.out.println(s2); if(s3.indexOf('b')= =0) System.out.println(s3); if(s4.indexOf('b')= =0) System.out.println(s4); if(s5.indexOf('b')= =0) System.out.println(s5); } }
【答案解析】