i have this problem with my code.
it need to put three names in alphabetical order that are entered from the user. then output the alphabetical result. the program compiles but when you put in different names there are not alphabeticals. i think only the first if works good. any help would be appreciated.
import javax.swing.JOptionPane; public class Sort { public static void main(String[] args) { String name1; String name2; String name3; name1 = JOptionPane.showInputDialog(null, "Enter a name"); name2 = JOptionPane.showInputDialog(null, "Enter second name"); name3 = JOptionPane.showInputDialog(null, "Enter third name"); if (name1.compareTo(name2) < 0) { if (name2.compareTo(name3) < 0) { JOptionPane.showMessageDialog(null, "Alphabetical order: \n" + name1 + "," + name2 + "," + name3); } else { JOptionPane.showMessageDialog(null, "Alphabetical order: \n" + name1 + "," + name3 + "," + name2); } } else if (name2.compareTo(name1) < 0) { if (name1.compareTo(name3) < 0) { JOptionPane.showMessageDialog(null, "Alphabetical order: \n" + name2 + "," + name1 + "," + name3); } else { JOptionPane.showMessageDialog(null, "Alphabetical order: \n" + name2 + "," + name3 + "," + name1); } } else if (name3.compareTo(name1) < 0) { if (name1.compareTo(name2) < 0) { JOptionPane.showMessageDialog(null, "Alphabetical order: \n" + name3 + "," + name1 + "," + name2); } else { JOptionPane.showMessageDialog(null, "Alphabetical order: \n" + name3 + "," + name2 + ","+ name1); } } } }