Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I pass a variable from one class to another?
    primarykey
    data
    text
    <p>So essentially what I want to do is to be able to:</p> <pre><code>class MainFile { public static void main(String args[]){ class2 TEObject = new class2(); int var1 = 1; int var2 = 1; int var3 = 1; int sc = 1; TEObject.method1(sc, var1, var2, var3); double[][] somearray = class2.out(somearray); System.out.println(somearray); } } </code></pre> <p>and here is the second class:</p> <pre><code> public class class2 { private double Mult; public double method1(int sc, int var1, int var2, int var3) { double[][] somearray = {{1,1,1,1,1,1,1,1,1,1,1,1}, {1,0.5,1,0.5,0.5,1,1,2,2,0.5,1,2}, {1,2,0.5,1,1,0.5,1,1,0.5,1,1,2}, {1,2,1,0.5,0.5,1,1,0.5,2,1,0.5,2}, {1,2,2,2,0.5,1,0.5,1,1,0.5,1,0.5}, {1,1,0.5,1,1,0.5,2,0.5,1,2,2,0.5}, {1,0.5,1,0.5,1,1,0.5,2,0.5,2,2,1}, {1,0.5,2,2,2,2,0.5,0.5,0.5,1,1,0.5}, {1,1,1,0.5,2,2,1,2,0.5,0.5,0.5,1}, {1,1,0.5,1,2,0.5,2,0.5,1,0.5,2,1}, {1,1,2,1,0.5,0.5,0.5,1,2,2,0.5,1}, {1,0.5,0.5,2,1,2,2,1,1,1,0.5,0.5}, }; Mult = somearray[sc][var1]*somearray[sc][var2]*somearray[sc][var3]; return Mult;//This needs to be returned for other methods in class2 } public static double[][] out(double[][] somearray){ return somearray; } //Some more methods go here </code></pre> <p>The problem I have here is that it asks me to put in a value when I try and call the method it says that the type is not applicable for the arguments. I can't put null there or else it will just print null.</p> <p>Failing this I essentially want a way to be able to output from a class to my main class so that I can manipulate the array within the main class.</p> <p>EDIT: I've updated the classes so they're more clear as to what I'm trying to do.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload