Java代码判断社区类型:居民委员会还是村民委员会
使用Java代码判断社区类型:居民委员会还是村民委员会
本文将展示如何使用Java代码判断一个字符串代表的社区类型是居民委员会还是村民委员会。
方法:
可以通过判断字符串是否包含'村民委员会'来判断是否为村民委员会。
代码示例:
public class CommitteeTypeChecker {
public static void main(String[] args) {
String committee1 = '雅冈社区居民委员会';
String committee2 = '许村村民委员会';
boolean isVillageCommittee1 = isVillageCommittee(committee1);
boolean isVillageCommittee2 = isVillageCommittee(committee2);
System.out.println(committee1 + ' 是村民委员会吗? ' + isVillageCommittee1);
System.out.println(committee2 + ' 是村民委员会吗? ' + isVillageCommittee2);
}
private static boolean isVillageCommittee(String committee) {
return committee.contains('村民委员会');
}
}
运行结果:
雅冈社区居民委员会 是村民委员会吗? false
许村村民委员会 是村民委员会吗? true
解释:
根据输出结果可以看出,'雅冈社区居民委员会'不包含'村民委员会',所以不是村民委员会;而'许村村民委员会'包含'村民委员会',所以是村民委员会。
总结:
本文提供了简单的Java代码示例,可以轻松判断一个字符串代表的社区类型是居民委员会还是村民委员会。您可以根据实际情况对代码进行修改和扩展,以满足您的需求。
原文地址: https://www.cveoy.top/t/topic/IOE 著作权归作者所有。请勿转载和采集!