How to print a boolean value?

Jayzpeer

I am trying to print out the boolean value, but it does not seem to work (I get an "unreachable statement" error and "missing return statement").

Here is my code:

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);
  }  
}   

Thanks !

dyzdyz010

Yeah you missed the return statement at the bottom. In fact, you can write this:

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;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related