我试图打印出 boolean 值,但它似乎不起作用(我收到“无法访问的语句”错误和“缺少返回语句”)。
这是我的代码:
public class DnaTest {
public static void main(String[] args){
aGoodBase('A');
}
public static boolean aGoodBase (char c) {
char [] charArray = { 'A', 'G', 'C', 'T' };
boolean aBase;
if (c == 'A' || c == 'G' || c == 'C' || c == 'T')
{
return true;
}
else
{
return false;
}
System.out.println(aBase);
}
}
谢谢!
最佳答案
是的,您错过了底部的返回声明。事实上,你可以这样写:
public static boolean aGoodBase (char c) {
char [] charArray = { 'A', 'G', 'C', 'T' };
boolean aBase;
if (c == 'A' || c == 'G' || c == 'C' || c == 'T')
{
aBase = true;
}
else
{
aBase = false;
}
System.out.println(aBase);
return aBase;
}
关于java - 如何打印 boolean 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32923687/