Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. public class Order {
  2.     public static String order(String words) {
  3.  
  4.         if (words.isEmpty()) {
  5.             return words;
  6.         }
  7.  
  8.         String[] splittedWords = words.split(" ");
  9.         String[] outputTab = new String[splittedWords.length];
  10.  
  11.         for (int i = 0; i < splittedWords.length; i++) {
  12.             String word = splittedWords[i];
  13.             for (int j = 0; j < word.length(); j++) {
  14.                 char c = word.charAt(j);
  15.                 if (c > 47 && c < 58) {
  16.                     int index = Character.getNumericValue(c);
  17.                     outputTab[index - 1] = word;
  18.                 }
  19.             }
  20.         }
  21.        
  22.         String combinedString = "";
  23.         for (String s : outputTab) {
  24.             combinedString += s + " ";
  25.         }
  26.  
  27.         return combinedString;
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement