java - 如何检查方法是否返回真或假?
问题描述
所以我有这个代码
public static boolean isVowel (char c) {
if (c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
{
return true;
}
else
{
return false;
}
}
这段代码有两个单独的方法
if (isVowel == true()) //I know this is wrong but how could I make it work?
{
//run command
}
else
{
//run command
}
如果是真的,我怎么做if (isVowel())
测试if isVowel
?
解决方案
public static boolean isVowel (char c) {
// concise code here
return (c=='a'|| c=='e'|| c=='i'|| c=='o'|| c=='u');
}
// your fix here
if (isVowel(aCharVariable)) {
// your code here
} else {
// your code here
}
简洁明了。
推荐阅读
- gtsummary - gtsummary 小数平均值和 SD - 更改默认值
- python - 如何在 Django 模型中实现一对值
- css - 从css中的另一个元素内部控制一个元素
- python - 如何为基于用户代理的 SIP 呼叫创建 IP 表防火墙规则
- sql - 使用 SQL 递归地将列中的层次结构分解为多列
- r - 用 tibble 创建一个表
- javascript - 谷歌表格问题用脚本函数复制单元格公式
- api - 错误请求:400,为 OAuth2.0 生成不记名令牌时
- spring-boot - 使用 Kubernetes 服务发现从 Spring Boot Admin 访问安全执行器
- kdb - 在同一端口上重新打开连接会导致文件描述符句柄错误