plz someone help me. i am not able to understand why evaluate function is not getting called
import java.util.Scanner; import java.io.*; interface Function { public int evaluate(int x); }
public class Half implements Function { int parameter , value,x;
public static void main ( String args[] ) { System.out.println("inside main"); Half a= new Half(); a.evaluate(int x); } public int evaluate(int x) { System.out.println("inside evaluate"); Scanner scan = new Scanner(System.in); System.out.println("Enter an integer :"); parameter= scan.nextInt(); System.out.println("hi"); value=parameter/2; System.out.println ("The value is :" + value); return value; }
That will get rid of the error that you are seeing but it will also uncover another error. The variable x hasn't been initialised (or entered by the user). You need to give a value to x or get a value for x from the user before calling the evaluate(int) function.