Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.ArrayList;
- public class Main {
- public static void main(String[] s) {
- Scanner userInput = new Scanner(System.in);
- //Array of words
- String [] words = {};
- boolean endOfInput = false;
- String temp;
- ArrayList<String> wordList = new ArrayList<>();
- do{
- System.out.println("Enter your word, type 000 to finish this");
- String userWord = userInput.nextLine();
- if(userWord == "000")
- {
- endOfInput = true;
- break;
- }
- else{
- wordList.add(userWord);
- }
- }
- while(endOfInput = false);
- if(wordList.size() == 0){
- System.out.println("No word is entered!");
- }
- for(int j = 0; j < wordList.size(); j++){
- for (int k = j + 1; k < wordList.size(); k++){
- if(words[j].compareTo(words[k])>0)
- {
- temp = words[j];
- words[j] = words[k];
- words[j] = temp;
- }
- }
- }
- System.out.print("Strings in Sorted Order:");
- for (int l = 0; l <= wordList.size() - 1; l++)
- {
- System.out.print(words[l] + ", ");
- }
- }
- }
RAW Paste Data