Hey guys, I'm having a little trouble with my Java homework. So far I'm stuck on problem 3.5, C). My code so far is:

package multadd;

/**
 *
 * @author Josh
 */
public class Main {

    public static void multadd (double a, double b, double c) {
 
System.out.println ( a * b + c);
    }

    public static void main(String[] args) {
    
 multadd ();

}
    }

C) asks that I "write a main method that tests multadd by invoking it with a few simple paramters). I'm confused on how I place the parameters for a, b, and c. Do I need to define the variables? When I try to define them in main, I get the error "cannot find symbol". Currently multadd (); gives me the error "method multadd class multadd.Main cannot be applied to given types. I just don't know what to tackle. An explanation would be greatly appreciated :)

it's all fine I suppose, you just need to give the method some parameters! you declared the variables in the header of your multadd method... whenever you write something like int x, or double some, you are declaring a parameter... hope this helps

I'm confused, I declared the variables with double a, b, and c. But I can't repeat this else It would be illegal. So do I just define the variables as is? Like so:

a = 1.0;
b = 2.0;
c = 3.0;

Even if I put this in multadd, when I try to invoke it in main it gives me the error "multadd.Main cannot be applied to given types" then it says double, double, double.

Member Avatar for coil

The parameters in a method exist only in that method. So, in the following method:

public int sum(int a, int b) { 
...
}

I can do an operation a+b. I can also access global variables. However, if I am outside the method, I cannot access a and b.

If you want to call the method sum, I need to supply two ints, according to the method header.

So I could call it like this:

sum(5, 6);

Alternatively, I could do:

int number1=5, number2=6;

sum(number1, number2);

Both do the same thing. Note that for the second way, the variable names don't have to be the same.

AH, alright. I understand now. Thank you so much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.