String s1 = "Lisi is Chinese"; if (s1.indexOf("is")==1){ String s2 = s1.replace("Lisi", "Zhangsan"); System.out.print(s1 + " "); System.out.println(s2); }else{ String s3 = s1.replace("Chinese", "American" A、Zhangsan is Chinese Zhangsan is Chinese B、Lisi is Chinese Zhangsan is Chinese C、Lisi is American D、Lisi is Chinese Lisi is Chinese
时间: 2024-03-12 21:50:02 浏览: 135
433-lisi雷迅紧固件大全.pdf
根据代码的逻辑,if语句中的条件判断为s1.indexOf("is")==1,而字符串s1中"Chinese"前面的字符是空格,因此"is"的索引是2,不等于1,所以if语句的条件判断为假,程序将执行else语句中的代码,即执行以下语句:
```String s3 = s1.replace("Chinese", "American");```
此时,s3被赋值为"Lisi is American",因为字符串s1不变,所以执行以下语句:
```System.out.print(s1 + " ");```
输出"Lisi is Chinese ",最后执行以下语句:
```System.out.println(s3);```
输出"Lisi is American",因此程序的输出结果是选项C、Lisi is American。
阅读全文