Reputation: 1
public static int displayResult(int num1, int num2){
return num1 * num2;
}
public static void main(String args[]){
displayResult(int num1, int num2);
}
When I try to run my eclipse, it shows an error which is "the method displayResult(int,int) in the type method is not applicable for the arguments". Anybody can explain to me how it works? Any help would be appreciated. Thanks.
Upvotes: 0
Views: 8569
Reputation: 6817
When you write the following
public static int displayResult(int num1, int num2){
return num1 * num2;
}
you're basically defining the method and specifying the argument types.
Invoking the method, however, is done as follows
displayResult(4,5);
Note that I can pass variables as well. The important point is that we don't give the type of the argument
Upvotes: 0
Reputation: 1863
What are you trying to accomplish with this? You need to pass integer values in to the parameters, the call you have does not do this. The integers are not initialized. The following examples will compile:
public static int displayResult(int num1, int num2){
return num1 * num2;
}
public static void main(String args[]){
displayResult(1, 1);
}
or...
public static int displayResult(int num1, int num2){
return num1 * num2;
}
public static void main(String args[]){
int num1 = 1;
int num2 = 1;
displayResult(num1, num2);
}
etc...
Upvotes: 0
Reputation: 2364
You need to pass actual number values in the displayResult() in main. So change it to something like displayResult(1, 5); It's saying it doesn't like the arguments (int num1, and int num2) because it expects an (int, int) to be passed in like (1, 5).
Upvotes: 0
Reputation: 129059
When you call displayResult
in main
, you need to actually pass it values, rather than repeat the types and names of the arguments. For example:
public static void main(String[] args){
displayResult(2, 3);
}
That should work, but it still won't do anything; displayResult
returns the result, but it doesn't print it or do anything else with it. You likely want to print it, probably using System.out.println
.
Upvotes: 1
Reputation: 6090
you need to define num1
and num2
before you can use them.
public static void main(String args[]){
int num1 = 3;
int num2 = -4;
displayResult(num1, num2);
}
Upvotes: 5