@Test public void whenEnterPalindromeThenResultMessagePalindrome() { String testWord = "КоМок"; System.setIn(new ByteArrayInputStream(testWord.getBytes())); new Palindrome().init(); assertThat(this.out.toString(), is(String.format("%s is palindrome%s", testWord, sep))); }
public void init() { final int MAX_LENGTH_OF_WORD = 5; try (Scanner sc = new Scanner(System.in)) { String line = sc.nextLine(); if (line.length() == MAX_LENGTH_OF_WORD) { StringBuilder sbReverseWord = new StringBuilder(); for (int i = line.length() - 1; i >= 0; i--) { sbReverseWord.append(line.charAt(i)); } if (line.toLowerCase().equals(sbReverseWord.toString().toLowerCase())) { print(line, "is palindrome"); } else { print(line, "is NOT palindrome"); } } else { print(line, "has not 5 symbols"); } } }
Palindrome { public void init() { final int MAX_LENGTH_OF_WORD = 5; try (Scanner sc = new Scanner(System.in)) { String line = sc.nextLine(); if (line.length() == MAX_LENGTH_OF_WORD) { StringBuilder sbReverseWord = new StringBuilder(); for (int i = line.length() - 1; i >= 0; i--) { sbReverseWord.append(line.charAt(i)); } if (line.toLowerCase().equals(sbReverseWord.toString().toLowerCase())) { print(line, "is palindrome"); } else { print(line, "is NOT palindrome"); } } else { print(line, "has not 5 symbols"); } } } }
Palindrome { public void init() { final int MAX_LENGTH_OF_WORD = 5; try (Scanner sc = new Scanner(System.in)) { String line = sc.nextLine(); if (line.length() == MAX_LENGTH_OF_WORD) { StringBuilder sbReverseWord = new StringBuilder(); for (int i = line.length() - 1; i >= 0; i--) { sbReverseWord.append(line.charAt(i)); } if (line.toLowerCase().equals(sbReverseWord.toString().toLowerCase())) { print(line, "is palindrome"); } else { print(line, "is NOT palindrome"); } } else { print(line, "has not 5 symbols"); } } }  }
Palindrome { public void init() { final int MAX_LENGTH_OF_WORD = 5; try (Scanner sc = new Scanner(System.in)) { String line = sc.nextLine(); if (line.length() == MAX_LENGTH_OF_WORD) { StringBuilder sbReverseWord = new StringBuilder(); for (int i = line.length() - 1; i >= 0; i--) { sbReverseWord.append(line.charAt(i)); } if (line.toLowerCase().equals(sbReverseWord.toString().toLowerCase())) { print(line, "is palindrome"); } else { print(line, "is NOT palindrome"); } } else { print(line, "has not 5 symbols"); } } }  void init(); }
Palindrome { public void init() { final int MAX_LENGTH_OF_WORD = 5; try (Scanner sc = new Scanner(System.in)) { String line = sc.nextLine(); if (line.length() == MAX_LENGTH_OF_WORD) { StringBuilder sbReverseWord = new StringBuilder(); for (int i = line.length() - 1; i >= 0; i--) { sbReverseWord.append(line.charAt(i)); } if (line.toLowerCase().equals(sbReverseWord.toString().toLowerCase())) { print(line, "is palindrome"); } else { print(line, "is NOT palindrome"); } } else { print(line, "has not 5 symbols"); } } }  void init();  }