Last active
May 25, 2020 02:30
-
-
Save lcruz/148492ab0d9bc7032879ee1c3bb72a58 to your computer and use it in GitHub Desktop.
Prueba Selección - Java
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
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.StringTokenizer; | |
public class Main { | |
public static void main(String[] args) { | |
} | |
public static String getMessage(String text) { | |
String result = ""; | |
StringTokenizer st = new StringTokenizer(text); | |
while (st.hasMoreTokens()) { | |
result = result.concat(String.valueOf(st.nextToken().charAt(0))); | |
} | |
return result; | |
} | |
public static String encrypt(String text) { | |
String result = ""; | |
for(int i=0; i<text.length(); i++) { | |
boolean duplicated = false; | |
for (int j = 0; j<text.length(); j++) { | |
if (text.charAt(i) == text.charAt(j) && i != j) { | |
duplicated = true; | |
} | |
} | |
if (!duplicated) { | |
result = result.concat(String.valueOf(text.charAt(i))); | |
} | |
} | |
return result; | |
} | |
public static int getLeast(String line, int givenNumber) { | |
StringTokenizer st = new StringTokenizer(line); | |
int[] numbers = new int[st.countTokens()]; | |
for (int i=0;st.hasMoreTokens(); i++) { | |
numbers[i] = Integer.parseInt(st.nextToken()); | |
} | |
Arrays.sort(numbers); | |
for(int i = 0; i < numbers.length; i++) { | |
if (numbers[i] > givenNumber) { | |
return numbers[i]; | |
} | |
} | |
return -1; | |
} | |
public static int fractile(int[] x, int p) { | |
Arrays.sort(x); | |
int position = p * x.length/100; | |
return x[position - 1]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment