Advertisement
dxvmxnd

Untitled

Nov 13th, 2023
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. public static String readFirstKeyFromConsole() {
  2. String str;
  3. boolean isNotCorrect;
  4.  
  5. do {
  6. isNotCorrect = false;
  7. System.out.println("Введите Str1(ключ): ");
  8. str = scanner.nextLine();
  9. System.out.println(str.length() + "ДЛИНА 1");
  10. for (int i = 0; i < str.length(); i++) {
  11. if (str.charAt(i) == ' ') {
  12. isNotCorrect = true;
  13. }
  14. }
  15. if (isNotCorrect) {
  16. System.out.println("Ключ не может содержать пробел! Повторите попытку.");
  17. }
  18. else {
  19. for (int i = 0; i < str.length(); i++) {
  20. for (int j = i+1; i < str.length(); j++) {
  21. if (str.charAt(i) == str.charAt(j)) {
  22. isNotCorrect = true;
  23. }
  24. }
  25. }
  26. if (isNotCorrect) {
  27. System.out.println("Символы не могут повторяться в ключе!");
  28. }
  29. }
  30. } while (isNotCorrect);
  31.  
  32. return str;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement