even or odd number using methods in java -


java code find or odd number using methods. please me getting below error.. compiler output

my code

class evenodd{ public static int evenodd(int num) {     if(num%2==0){         system.out.println("true");     }     else         { system.out.println("false"); } public static void main(string[] args) {     int evenodd=evenodd(9); } } 

}

public static int evenodd(int num) {     if(num%2==0){         system.out.println("true");     }     else         { system.out.println("false"); } 

this method missing return statement. wrote method as

static int 

but didn't write return statement. instead printing.

try code:

class evenodd{     public static boolean evenodd(int num) {             if(num%2==0){                 return true;             }         return false;     }     public static void main(string[] args) {          boolean iseven=evenodd(9);            system.out.println(iseven);     } } 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -