Best shuffle: Difference between revisions

→‎{{header|Java}}: some idiot removed the shuffle
(Undo revision 144122 by Fwend (talk))
(→‎{{header|Java}}: some idiot removed the shuffle)
Line 1,415:
=={{header|Java}}==
Translation of [[Best_shuffle#Icon_and_Unicon|Icon]] via [[Best_shuffle#AWK|AWK]]
<lang java>publicimport class BestShuffle {java.util.*;
 
public class BestShuffle {
 
public static void main(String[] args) {
String[] words = {"abracadabra", "seesaw", "grrrrrr", "pop", "up", "a"};
Line 1,424 ⟶ 1,427:
public static String bestShuffle(final String s1) {
char[] s2 = s1.toCharArray();
Collections.shuffle(Arrays.asList(s2));
for (int i = 0; i < s2.length; i++) {
if (s2[i] != s1.charAt(i)) continue;
continue;
for (int j = 0; j < s2.length; j++) {
if (s2[i] != s2[j] && s2[i] != s1.charAt(j) && s2[j] != s1.charAt(i)) {
Line 1,440 ⟶ 1,445:
private static int count(final String s1, final char[] s2) {
int count = 0;
for (int i = 0; i < s2.length; i++)
if (s1.charAt(i) == s2[i]) count++;
count++;
return count;
}
Anonymous user