Last active
December 26, 2015 00:49
-
-
Save kazoo04/7067261 to your computer and use it in GitHub Desktop.
@s0bc
This file contains hidden or 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.Random; | |
public class RandomChars | |
{ | |
private final static String answer = "あいうえ"; | |
public static int count = 0; | |
public static void main(String[] args) | |
{ | |
char[] chars = answer.toCharArray(); | |
String strs = ""; | |
while(!strs.equals(answer)) | |
{ | |
count++; | |
if(strs.length() >= answer.length()) { | |
strs = strs.substring(1, answer.length()); | |
} | |
char c = chars[(int)(Math.random() * chars.length)]; | |
strs += c; | |
System.out.print(c); | |
} | |
System.out.println("\ncount = " + count); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment