Skip to content

Instantly share code, notes, and snippets.

@guoguo12
Created January 25, 2018 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guoguo12/ff6305e96f274353f33173780b7ebe53 to your computer and use it in GitHub Desktop.
Save guoguo12/ff6305e96f274353f33173780b7ebe53 to your computer and use it in GitHub Desktop.
import java.util.Arrays;
public class QuikMaths {
public static void multiplyBy3(int[] A) {
for (int x: A) {
x = x * 3;
}
}
public static void multiplyBy2(int[] A) {
int[] B = A;
for (int i = 0; i < B.length; i += 1) {
B[i] *= 2;
}
}
public static void swap(int A, int B) {
int temp = B;
B = A;
A = temp;
}
public static void main(String[] args) {
int[] arr;
arr = new int[] {2, 3, 3, 4};
multiplyBy3(arr);
System.out.println(Arrays.toString(arr));
arr = new int[] {2, 3, 3, 4};
multiplyBy2(arr);
System.out.println(Arrays.toString(arr));
int a = 6;
int b = 7;
swap(a, b);
System.out.println(a + " " + b);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment