Advertisement
darkor

oop_lab_4

Mar 3rd, 2020
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. package com.company;
  2.  
  3. public class Main
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.         String string = "London    is       the       capital  of     Great     Britain";
  8.         System.out.println("Before: " + string);
  9.         string = string.trim().replaceAll(" +", " ");
  10.         String[] array = string.split(" ");
  11.         int len = array.length - 1;
  12.         String new_string = array[len];
  13.         for (int i = len - 1; i >= 0; i--)
  14.             new_string = new_string + " " + array[i];
  15.         System.out.println("After: " + new_string);
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement