Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1.  
  2.  
  3. public class BackwardsSentence {
  4.     public static void main(String[] arguments) {
  5.         int numberOfWords = arguments.length;
  6.         if (numberOfWords > 0){
  7.             String sentence = arguments[0];
  8.             int count = 1;
  9.  
  10.  
  11.             while (count < numberOfWords){
  12.                 sentence += " ";
  13.                 sentence += arguments[count++];
  14.             }
  15.  
  16.             System.out.println(sentence);
  17.  
  18.             for (int i = sentence.length(); i > 1; i--) {
  19.                 int j = sentence.length() - i;
  20.                 String newSentence = "";
  21.                 newSentence += sentence.substring(0, j);
  22.                 newSentence += sentence.charAt(sentence.length() - 1);
  23.                 newSentence += sentence.substring(j, sentence.length() - 1);
  24.                 sentence = newSentence;
  25.                 System.out.println(sentence);
  26.             }
  27.  
  28.         }
  29.         else System.out.println("Program wywołano bez parametrów !");
  30.  
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement