Reputation: 77
I just started studying how to code in the Java programming language.
I was given a problem that told me to pass numbers, variables, and expressions as arguments to a procedure call. The problem I am having is that I get an error when I tried to pass numbers, variables and expressions as arguments to the procedure call (I got 27 errors).
Below is my code, and I would really appreciate it if anyone could point out what is wrong with my code. Thank you.
public class test {
// this is the procedure definition
public static int computeCost ( int quantity , int price ) {
return quantity * price;
}
public static void main ( String args[] )
// passing numbers as arguments to the procedure call "cost"
System.out.println ( computeCost ( 7 , 12 ) );
// passing variables as arguments to the procedure call "cost"
int a = 5;
int b = 7;
System.out.println ( computeCost ( a , b ) );
// passing expressions as arguments to the procedure call "cost
System.out.println ( computeCost ( 1 + 2 + 3 + 4, 5 + 6 + 7 + 8 ) );
}
}
Upvotes: 0
Views: 243
Reputation: 11
Just a tip. Sometimes too many errors just corresponds to a missing piece of code. Look for every possible cases.
Upvotes: 0
Reputation: 975
You are missing an opening bracket on your main method.
public class Test
{
// this is the procedure definition
public static int computeCost(int quantity, int price)
{
return quantity * price;
}
public static void main(String args[])
{// <--MISSING
// passing numbers as arguments to the procedure call "cost"
System.out.println(computeCost(7, 12));
// passing variables as arguments to the procedure call "cost"
int a = 5;
int b = 7;
System.out.println(computeCost(a, b));
// passing expressions as arguments to the procedure call "cost
System.out.println(computeCost(1 + 2 + 3 + 4, 5 + 6 + 7 + 8));
}
}
Upvotes: 3
Reputation: 46415
You are missing the opening {
in your definition of main
!
public static void main ( String args[] )
should be
public static void main ( String args[] ) {
Upvotes: 2
Reputation: 10810
I see what's wrong. You don't have an opening bracket after your main(..) method. All methods in Java must have their code surrounded with {
and }
.
Change this:
public static void main ( String args[] )
to this:
public static void main ( String args[] ) {
Other than that your code looks perfectly fine to me.
Upvotes: 5