Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Internet & the Web (https://www.askmehelpdesk.com/forumdisplay.php?f=177)
-   -   Java: using an array from the main in a method (https://www.askmehelpdesk.com/showthread.php?t=4489)

  • Jul 23, 2003, 08:04 AM
    kilroy
    Java: using an array from the main in a method
    I have the array names[][] in the main of my program and I want to use it in a method FindName..
    How would I wright the method header and the call to the method in the main?
  • Jul 23, 2003, 08:44 AM
    kilroy
    Java: using an array from the main in a method
    The array is a string array
  • Jul 30, 2003, 12:37 PM
    Deschwann
    Java: using an array from the main in a method
    OK, first of all you can't call the method directly from the main unless your method is static.

    example

    public class className{

    static method(String[][] name){

    }

    public static void main(String args[]){

    String name[][];
    //fill the string here
    method(name);
    }
    }

    your second choice is to make an object of your class and use the method

    public class className{

    public method(String[][] name){

    }

    public static void main(String args[]){

    String name[][];
    //fill the string here

    className copyOfClass = new className();
    copyOfClass.method(name);
    }
    }

  • All times are GMT -7. The time now is 09:20 PM.