Skip to content

Instantly share code, notes, and snippets.

@Venipa
Created May 16, 2018 10:10
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 Venipa/9ace179cd79b968540a9e58053a53698 to your computer and use it in GitHub Desktop.
Save Venipa/9ace179cd79b968540a9e58053a53698 to your computer and use it in GitHub Desktop.
package banknoten;
import java.util.Random;
import java.util.Scanner;
public class Helper {
public static String ReadLine() {
return ReadLine(new Scanner(System.in), 0);
}
public static String ReadLine(Scanner sc, int musthaveLength) {
if (sc.hasNext()) sc.nextLine();
String res = "";
if(musthaveLength != 0) {
while(res.trim().length() != musthaveLength) {
res = sc.nextLine();
System.out.println(res.trim().length());
}
} else {
res = sc.nextLine();
}
return res;
}
public static String RandString(int length) {
String characters = "abcdefghijklmnopqrstuvwxyz";
characters += characters.toUpperCase();
char[] _chars = characters.toCharArray();
StringBuilder sb = new StringBuilder();
for (int i : new int[length]) {
sb.append(Character.toString(_chars[new Random(((length-1 < 0 || length-1 > _chars.length) ? 0 : length)).nextInt()]));
}
return sb.toString();
}
public static int getLatinIndex(char input) {
char[] _latinchars = "abcdefghijklmnopqrstuvwxyz".toUpperCase().toCharArray();
char _char = Character.toString(input).toUpperCase().charAt(0);
int counter = 0;
for(char c : _latinchars) {
if(_char == c) return counter;
counter++;
}
return -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment