Click here to Skip to main content
15,888,126 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im sort of new to coding
I want to add a parameter to a method


but when I type it in, the jgrasp says no main method was found.

I think it wants to see the
public static void main(String[] args)
but my teacher said I can put the method in instead.

What I have tried:

public static void methodName (intx, inty)
Posted
Updated 26-Jan-18 20:52pm
v2
Comments
PIEBALDconsult 26-Jan-18 20:42pm    
The language requires the main function to have a certain signature (or one of a few pre-defined signatures); you can't just change it.
What are you trying to accomplish?

1 solution

You can't add parameters to main - it needs to have a specific signature - which means it needs to have very specific input and output parameters, and you adding or removing them changes the method signature and means that the system doesn't "see it" when it looks for the method to call at startup.

You can create a new method, with whatever parameters you like, and call that from your main method:
C#
private static int MyMethod(int x, int y)
   {
   return x * y;
   }
public static void main(string[] args)
   {
   for (int i = 0; i < 10; i++)
      {
      Console.WriteLine(MyMethod((i , i + 1));
      }
   }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900