C
Char
Gast
Moin, bei C# gibts ne Möglichkeit eine Methode aufzurufen und Variablen mitzugeben die dann in der Methode neu gesetzt werden. Gibt es in java was ähnliches?
@x.l hat gesagt.:Anstelle von bspw. int musst du Integer verwenden. Das heißt keine primitiven Datentypen.
BTW: Du meinst sowas wie out-Parameter in C#, oder?
Integer w = 0;
Integer h = 0;
String s=methode(w,h);
System.out.println(w,h);
public String methode(w,h)
{
w=1;
h=2;
}
public class Test{
public static void main(String[] args){
VariablenContainer myVC = new VariablenContainer(0,0);
increase(myVC);
System.out.println(myVC.a);
System.out.println(myVC.b);
}
public static void increase(VariablenContainer vc){
vc.a = vc.a+5;
++vc.b;
}
}
class VariablenContainer{
int a;
int b;
public VariablenContainer(int a, int b){
this.a = a;
this.b = b;
}
}