ivanakarpuzova

Untitled

Feb 9th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. import java.util.*;
  2. /*
  3. Sample Input: Sample Output:
  4. remetoV enesd e ostad oncevos. Vremeto denes e dosta soncevo.
  5. */
  6.  
  7. public class PrevrtiZborovi {
  8.  
  9. public static String fix(String s) {
  10. char[] word = s.toCharArray();
  11. char[] fixedArray = new char[word.length];
  12. int index = 1;
  13. String fixed;
  14. char lastChar;
  15.  
  16. if(s.contains(".")) {
  17. lastChar = s.charAt(s.length() - 2);
  18. fixedArray[0] = lastChar;
  19. for(int i = 0; i < word.length-2; i++) {
  20. fixedArray[index] = word[i];
  21. ++index;
  22. }
  23. fixed = new String(fixedArray);
  24. fixed = fixed.concat(".");
  25. }
  26.  
  27. else {
  28. lastChar = s.charAt(s.length() - 1);
  29. fixedArray[0] = lastChar;
  30. for(int i = 0; i < word.length-1; i++) {
  31. fixedArray[index] = word[i];
  32. ++index;
  33. }
  34. fixed = new String(fixedArray);
  35. }
  36. return fixed;
  37. }
  38. public static void main(String[] args) {
  39. ArrayList<String> list = new ArrayList<String>();
  40. Scanner input = new Scanner(System.in);
  41.  
  42. boolean flag = true;
  43. while(flag == true) {
  44. String expression = input.next();
  45. if(expression.contains(".")) {
  46. flag = false;
  47. }
  48. list.add(fix(expression));
  49. }
  50. for(String s : list) {
  51. System.out.print(s + " ");
  52. }
  53. }
  54.  
  55. }
Add Comment
Please, Sign In to add comment