Advertisement
roronoa

split string en mots et commencer par derniers mots

Aug 18th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.math.*;
  4.  
  5. class Solution {
  6.  
  7.     public static void main(String args[]) {
  8.         Scanner in = new Scanner(System.in);
  9.         String S = in.nextLine();
  10.         int fin = S.length()-1;
  11.         for(int i = S.length()-1; i >= 0; i--)
  12.         {
  13.             if(S.charAt(i) == ' ')
  14.             {
  15.                 for(int j = i+1; j <= fin; j++)
  16.                     System.out.print(S.charAt(j));
  17.                 System.out.print(" ");
  18.                 fin = i-1;
  19.             }
  20.             if(i == 0)
  21.             {
  22.                 for(int j = i; j <= fin; j++)
  23.                     System.out.print(S.charAt(j));
  24.             }
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement