Find odd number using function- error displayed "method must return int" | Selenium Training|Java|WebDriver|TestNG|Frameworks|Videos
10% July Month Discount Avail now

Selenium Training Forum

find odd number using function- error displayed "method must return int"

V
Vivek Post on 08/06/2019


public class oddnum {


public static void main(String[] args) {
int O=odd(100);
System.out.println(O);
}

public static int odd(int num){

for(int i=2; i<=num; i++){
if(i%2==0){
return i;
}
}
}
}

S

Instructor

Support Team Reply on 12/06/2019

You need to return an integer outside the for loop as well.