Jump to content

General Java help


Recommended Posts

Posted
1 hour ago, toomaz109 said:

public class MyClass {

                  public static void main (String[] args) {

                                    int x = 5;

                                    addOneTo(x);

                                    System.out.println(x);

                  }

 

                  static void addOneTo (int num) {

                               //You have to pre increment to see the result after referencing x

                                    ++num;

                  }

}

That isn't the issue which is occuring.

Posted
On 4/8/2017 at 2:22 PM, toomaz109 said:

public class MyClass {

                  public static void main (String[] args) {

                                    int x = 5;

                                    addOneTo(x);

                                    System.out.println(x);

                  }

 

                  static void addOneTo (int num) {

                               //You have to pre increment to see the result after referencing x

                                    ++num;

                  }

}

naw niga

 

java passes by value, not reference. u can add a billion to num, but its still gonna output 5

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...