Last active
August 6, 2024 07:09
-
-
Save sunmeat/970123e6bc867076bb21 to your computer and use it in GitHub Desktop.
methods example # 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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