Created
October 27, 2012 11:01
-
-
Save maknoll/3964287 to your computer and use it in GitHub Desktop.
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
1) | |
public class Median { | |
public static int median(int a, int b, int c) { | |
if (a < b) { | |
if (b < c) | |
return b; | |
else | |
return c; | |
} | |
else { | |
if (a < c) | |
return a; | |
else | |
return c; | |
} | |
} | |
public static int median2(int a, int b, int c) { | |
int[] arr = new int[3]; | |
arr[0] = a; | |
arr[1] = b; | |
arr[2] = c; | |
java.util.Arrays.sort(arr); | |
return arr[1]; | |
} | |
} | |
3) | |
public class Transform { | |
public static String transform(int dez, int basis) { | |
String result = new String(); | |
String[] alphabet = { "0", "1", "2", "3", "4", "5", "6", "7", | |
"8", "9", "a", "b", "c", "d", "e", "f" }; | |
while (dez > 0) { | |
result = alphabet[dez % basis] + result; | |
dez /= basis; | |
} | |
return result; | |
} | |
} | |
4) | |
public class MyIntArray { | |
public static int[] create(int n) { | |
int arr[] = new int[n]; | |
for (int i = 0; i < n; i++) { | |
arr[i] = 5 + (int)(94*Math.random()); | |
} | |
return arr; | |
} | |
public static String toString(int[] a){ | |
String s = new String(); | |
for (int i : a) { | |
s += i + " "; | |
} | |
return s; | |
} | |
public static int posMin(int[] a) { | |
int min = 100; | |
int minPos = 0; | |
for (int i = 0; i < a.length; i++) { | |
if (a[i] < min) { | |
min = a[i]; | |
minPos = i; | |
} | |
} | |
return minPos; | |
} | |
public static int specialSum(int[] a) { | |
int i = 0; | |
for (int e : a) | |
if (e % 4 * e % 13 != 0) i += e; | |
return i; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment