Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BackwardsSentence {
- public static void main(String[] arguments) {
- int numberOfWords = arguments.length;
- if (numberOfWords > 0){
- String sentence = arguments[0];
- int count = 1;
- while (count < numberOfWords){
- sentence += " ";
- sentence += arguments[count++];
- }
- System.out.println(sentence);
- for (int i = sentence.length(); i > 1; i--) {
- int j = sentence.length() - i;
- String newSentence = "";
- newSentence += sentence.substring(0, j);
- newSentence += sentence.charAt(sentence.length() - 1);
- newSentence += sentence.substring(j, sentence.length() - 1);
- sentence = newSentence;
- System.out.println(sentence);
- }
- }
- else System.out.println("Program wywołano bez parametrów !");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement