I'm currently in my first semester. I have a project requiring me to build a program having a user input 3 words, sort them alphabetically and output the middle word. I have done some searching and seem to only come back with results for sorting 2 words. I so far have code to get the user input but I am completely lost as to how to sort them alphabetically. Please be patient with me as I am very new to programming. If anyone can provide me with any advice or the best or easiest way to go about sorting these I would greatly appreciate it
import java.util.Scanner; //The Scanner is in the java.util package. public class MiddleString { public static void main(String [] args){ Scanner input = new Scanner(System.in); //Create a Scanner object. String str1, str2, str3; System.out.println("Please enter three word words : "); //Prompt user to enter the three words str1=input.next(); //Sets "str1" = to first word. str2=input.next(); //Sets "str2" = to second word. str3=input.next(); //Sets "str3" = to third word. System.out.println("The middle word is " ); // Outputs the middle word in alphabetical order. } }
we havnt done arrays yet and I THINK i have to do compareTo.....if so can someone please show me example on how to use it?