Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- public class Main
- {
- public static void main(String[] args)
- {
- String string = "London is the capital of Great Britain";
- System.out.println("Before: " + string);
- string = string.trim().replaceAll(" +", " ");
- String[] array = string.split(" ");
- int len = array.length - 1;
- String new_string = array[len];
- for (int i = len - 1; i >= 0; i--)
- new_string = new_string + " " + array[i];
- System.out.println("After: " + new_string);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement