Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- /*
- Sample Input: Sample Output:
- remetoV enesd e ostad oncevos. Vremeto denes e dosta soncevo.
- */
- public class PrevrtiZborovi {
- public static String fix(String s) {
- char[] word = s.toCharArray();
- char[] fixedArray = new char[word.length];
- int index = 1;
- String fixed;
- char lastChar;
- if(s.contains(".")) {
- lastChar = s.charAt(s.length() - 2);
- fixedArray[0] = lastChar;
- for(int i = 0; i < word.length-2; i++) {
- fixedArray[index] = word[i];
- ++index;
- }
- fixed = new String(fixedArray);
- fixed = fixed.concat(".");
- }
- else {
- lastChar = s.charAt(s.length() - 1);
- fixedArray[0] = lastChar;
- for(int i = 0; i < word.length-1; i++) {
- fixedArray[index] = word[i];
- ++index;
- }
- fixed = new String(fixedArray);
- }
- return fixed;
- }
- public static void main(String[] args) {
- ArrayList<String> list = new ArrayList<String>();
- Scanner input = new Scanner(System.in);
- boolean flag = true;
- while(flag == true) {
- String expression = input.next();
- if(expression.contains(".")) {
- flag = false;
- }
- list.add(fix(expression));
- }
- for(String s : list) {
- System.out.print(s + " ");
- }
- }
- }
Add Comment
Please, Sign In to add comment