java - How do I move two parallel arrays from one method to another, by returning to the main method then entering the second one? -


i need both string , double arrays go inputaccept table:

    inputaccept();      table(names, costs);      public static void inputaccept() {            scanner scan = new scanner(system.in);            string[] names = {"","","","","","","","","",""};            double[] costs = new double[10];              (int = 0; < 10; i++)             {                 system.out.println("enter name of item " + (i + 1) + ": ");                 names[i] = scan.nextline();                 system.out.println("enter item cost: ");                 costs[i] = scan.nextdouble();             }      }      public static void table(string[] names, double[] costs) {     //insert code using arrays     } 

i know wrong, don't know fix it.

you can create 2 arrays in main method, first pass them inputaccept method, pass 2 arrays table method:

    public static void main(string[] args) {         double[] costs = new double[10];         string[] names = {"","","","","","","","","",""};         inputaccept(names, costs);         table(names, costs);     }      public static void inputaccept(string[] names, double[] costs) {         scanner scan = new scanner(system.in);         (int = 0; < 10; i++)         {             system.out.println("enter name of item " + (i + 1) + ": ");             names[i] = scan.nextline();             system.out.println("enter item cost: ");             costs[i] = scan.nextdouble();         }     }      public static void table(string[] names, double[] costs) {     //insert code using arrays     } 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -