Question: Write a Java program that reads a sentence consisting of four words and prints all of the 4 ! permutations of the four words in

Write a Java program that reads a sentence consisting of four words and prints all of the 4! permutations of the four words in order. For example, if sentence "earth rotates around sun" is entered, the program should print
"earth rotates around sun" "earth rotates sun around" "earth around rotates sun" "earth around sun rotates" "earth sun rotates around" "earth sun around rotates" "rotates earth around sun" "rotates earth sun around" "rotates around earth sun" "rotates around sun earth" "rotates sun earth around" "rotates sun around earth" "around earth rotates sun" "around earth sun rotates" "around rotates earth sun" "around rotates sun earth" "around sun earth rotates" "around sun rotates earth" "sun earth rotates around" "sun earth around rotates" "sun rotates earth around" "sun rotates around earth" "sun around earth rotates" "sun around rotates earth"
Note that entire sentence should be read once using nextLine() method and indexOf() and substring() methods should be used to extract each word. Other String build-in methods are not allowed.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!