Advertisement
sudoaptinstallname

Untitled

Feb 4th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.*;
  4. import java.util.Scanner;
  5.  
  6. public class helloWorld {
  7. public static void main(String [] args)
  8. {
  9. System.out.print("Input String: ");
  10. Scanner input = new Scanner(System.in);
  11. String word = input.nextLine();
  12. int count = 0;
  13. String temp;
  14. char[] current = new char[word.length()];
  15. Random rand = new Random();
  16. int x;
  17. int y;
  18. do {
  19. for (x = 0; x < word.length(); x++)
  20. {
  21. if (current[x] != word.charAt(x))
  22. {
  23. current[x] = (char) (rand.nextInt(91)+32);
  24. //Completely random, does not check against a list of previous attempts.
  25.  
  26. }
  27. }
  28. temp ="";
  29. for (y = 0; y<current.length; y++)
  30. temp+=current[y];
  31. System.out.println(temp);
  32. count++;
  33.  
  34. } while (!temp.equals(word));
  35. System.out.println();
  36. System.out.println(count+" Iterations");
  37.  
  38.  
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement