Return boolean in java? -


i need on question.

"inside chknum class,the method ineven()return if value passed " even.it return false odd.therefore iseven()has return type of boolean."

also line below cannot changed.

if(e.ineven(10))system.out.println("10 even");  if(e.ineven(9))system.out.println("9 even");  if(e.ineven(8))system.out.println("8 even");" 

i beginner in java. try finish question following program.anyway, doesn't work.=( doing wrong?

public class chknum{      boolean ineven=true;      public boolean ineven(int o)     {         if ((o%2)==0)         {             ineven= true;         }         else         {             ineven = false;         }         return ineven;     }  }  class main{     public static void main(string args[])     {         chknum e=new chknum();          if(e.ineven(10))system.out.println("10 even");         if(e.ineven(9))system.out.println("9 even");         if(e.ineven(8))system.out.println("8 even");       } } 

if you'd indent code, you'd find problem :

public boolean ineven(int o) {     if ((o%2)==0) {          ineven = true;     }  else  {          ineven = false;     }     return ineven;          } // remove     ; // remove } 

it make more sense make ineven local variable (i.e. declare inside ineven method).


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -