Hi guys, I'm brand-new to Java, self-teaching. If one of the wizards could tell me what I'm doing wrong here, or ideally give me a better way to solve this problem, I'd be eternally appreciative.
The challenge is incredibly simple, but I only want to use functions, classes or objects that I've referenced in the code below - there's not point me using more advanced functions when I haven't learnt them yet.
The idea is to ask for 3 names from the user, sort them and return them in alphabetical order to the user. I want to use the scanner class for input.
My issue is that my code below has compilation errors which I don't understand.
//Sorted names //Ask the user to enter three names //Return the names in alphabetic order import javax.swing.JOptionPane; import java.util.Scanner; public class Challenge007Prompt { public static void main(String args[]) { String name1, name2, name3; char name1Char, name2Char, name3Char; char name1CharStr, name2CharStr, name3CharStr; String firstChar, secondChar, thirdChar; Scanner keyboard = new Scanner(System.in); System.out.println("Please enter the first name"); name1 = keyboard.nextLine(); System.out.println("First name is: " + name1); System.out.println("Please enter the second name"); name2 = keyboard.nextLine(); System.out.println("Second name is: " + name2); System.out.println("Please enter the third name"); name3 = keyboard.nextLine(); System.out.println("Third name is: " + name3); name1Char = name1.charAt(0); name2Char = name2.charAt(0); name3Char = name3.charAt(0); if(name1Char < name2Char && name1Char < name3Char) firstChar=name1; else if(name2Char < name1Char && name2Char < name3Char) firstChar=name2; else if(name3Char < name1Char && name3Char < name2Char) firstChar=name3; if(name1Char > name2Char && name1Char > name3Char) thirdChar=name1; else if(name2Char > name1Char && name2Char > name3Char) thirdChar=name2; else if(name3Char > name1Char && name3Char > name2Char) thirdChar=name3; name1CharStr = firstChar.charAt(0); name2CharStr = secondChar.charAt(0); name3CharStr = thirdChar.charAt(0); if(name1Char==name1CharStr || name1Char==name3CharStr) secondChar=name1; else if(name2Char==name1CharStr || name1Char==name3CharStr) secondChar=name2; else secondChar=name3; System.out.println(firstChar + secondChar + thirdChar); System.exit(0); } }