Guest User

Untitled

a guest
Mar 23rd, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. package com.javarush.task.task22.task2203;
  2.  
  3. /*
  4. Между табуляциями
  5. */
  6. public class Solution {
  7. public static String getPartOfString(String string) throws TooShortStringException {
  8. if (string == null || string.isEmpty())
  9. {
  10. throw new TooShortStringException();
  11. }
  12. int indexOfFirstTab = string.indexOf("\t");
  13. if (indexOfFirstTab == -1)
  14. throw new TooShortStringException();
  15. int indexOfSecondTab = string.indexOf("\t", indexOfFirstTab + 1);
  16. if (indexOfSecondTab == -1)
  17. throw new TooShortStringException();
  18. return string.substring(indexOfFirstTab + 1, indexOfSecondTab);
  19. }
  20.  
  21. public static class TooShortStringException extends Exception {
  22. public TooShortStringException() {
  23. super();
  24. }
  25.  
  26. }
  27.  
  28. public static void main(String[] args) throws TooShortStringException {
  29. System.out.println(getPartOfString("\tJavaRush - лучший сервис \tобучения Java\t."));
  30. }
  31. }
Add Comment
Please, Sign In to add comment