判断如果字符串数组list里包含“CPJL”,则返回1
时间: 2024-04-30 21:22:19 浏览: 10
Python语言的实现:
```python
def has_CPJL(list):
for s in list:
if "CPJL" in s:
return 1
return 0
```
说明:遍历字符串数组list,如果发现有字符串包含“CPJL”,则返回1,否则返回0。
相关问题
java中判断如果字符串数组list里包含“CPJL”,则返回1
可以使用for循环遍历字符串数组,判断数组中是否包含特定字符串,如果包含则返回1,否则返回0。
示例代码如下:
```
public static int containsCPJL(String[] list) {
for (String str : list) {
if (str.equals("CPJL")) {
return 1;
}
}
return 0;
}
```
使用方法:
```
String[] list = {"AA", "BB", "CPJL", "DD"};
int result = containsCPJL(list);
System.out.println(result); //输出1
```
假设字符串数组里有3个值,java中判断如果字符串数组list里包含“CPJL”,则返回1
Java代码实现:
```
String[] list = {"abc", "CPJL", "xyz"};
for (String str : list) {
if (str.equals("CPJL")) {
return 1;
}
}
return 0;
```
解释:
首先定义一个字符串数组list,包含三个值。使用for循环遍历数组中的每一个元素,判断该元素是否等于“CPJL”,如果相等则返回1。如果循环结束都没有找到“CPJL”,则返回0。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)