GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — programming/problems/dynamic-programming/RandomString.java at master · rp-code9/programming Expand file tree/ Copy pathRandomString.javaMore file actions 53 lines (45 loc) · 1.49 KB / Copy pathRandomString.javaFile metadata and controls53 lines (45 loc) · 1.49 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 import java.util.Random; // generate pesudorandom strings class RandomString { public static final int GENOME = 1; public static final int LOWER = 2; public static final int UPPER = 3; private static char[] getAlphabets(int c) { String s = ""; switch(c) { case GENOME: s = "ACTG"; break; case UPPER: s = "ABCDEFGHIJKLMNOPQRSUVWXYZ"; break; case LOWER: s = "abcdefghijklmnopqrstuvwxyz"; break; default: s = "Aa1"; break; } return s.toCharArray(); } public static String nextString(int length, char[] alphabets) { int upper = alphabets.length; Random random = new Random(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < length; ++i) { int index = random.nextInt(upper); sb.append(alphabets[index]); } return sb.toString(); } public static String nextString(int length, int choice) { char[] array = getAlphabets(choice); return nextString(length, array); } public static void main(String[] args) { int length = 10; System.out.println(RandomString.nextString(length, RandomString.GENOME)); System.out.println(RandomString.nextString(length, RandomString.UPPER)); System.out.println(RandomString.nextString(length, RandomString.LOWER)); } } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |