Skip to content

Instantly share code, notes, and snippets.

@sunmeat
Last active August 6, 2024 07:09
Show Gist options
  • Save sunmeat/970123e6bc867076bb21 to your computer and use it in GitHub Desktop.
Save sunmeat/970123e6bc867076bb21 to your computer and use it in GitHub Desktop.
methods example # 3
package com.alex.methods;
public class JavaApplication1 {
static void swap(int a, int b) {
int temp = a;
a = b;
b = temp;
}
public static void main(String[] args) {
int streetMagic = 10;
int hogwartsMagic = 15;
streetMagic = streetMagic + hogwartsMagic - (hogwartsMagic = streetMagic);
System.out.println(streetMagic); // 15
System.out.println(hogwartsMagic); // 10
// before change
swap(streetMagic, hogwartsMagic);
// after change
System.out.println(streetMagic); // 15
System.out.println(hogwartsMagic); // 10
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment