import java.util.Scanner;
public class alphabetical {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner Alphabet= new Scanner(System.in);
System.out.println("Input First Name");
String UserInput= Alphabet.next();
System.out.println("Input second name");
String UserInput2= Alphabet.next();
System.out.println("Input third name");
String UserInput3= Alphabet.next();
System.out.println(alpha)UserInput,UserInput2,UserInput3));
}
public static void alpha(String fromUser,String fromUser2, String fromUser3)
{
if (fromUser.compareTo(fromUser2)>0)
{
System.out.println(fromUser2);
}
else if(fromUser.compareTo(fromUser3)>0)
{
System.out.println(fromUser3);
}
else if (fromUser2.compareTo(fromUser3)>0)
{
System.out.println(fromUser3);
}
else if (fromUser2.compareTo(fromUser)>0)
{
System.out.println(fromUser);
}
else if (fromUser3.compareTo(fromUser)>0)
{
System.out.println(fromUser);
}
else if (fromUser3.compareTo(fromUser2)>0)
{
System.out.println(fromUser2);
}
}
}
So that's my code but I don't know what I'm doing wrong. I've been working on this for a while and I need a code that will allow the user to input 3 names and then sort the names in alphabetical order
The requirements for this program is to have the user input 3 strings and print them out ordered alphabetically using a function that takes 3 strings-- the return type should be void-- this means that there nothing returned back to main, the function will just print out the three words in alphabetical order there should be 6 cases you need to worry about (think If, elseif...else). Here is what a sample output might look like in the console (> denotes it's in the console-- you won't actually see this):
input first lowercase string
awesome
input second lowercase string
bogus
input third lowercase string
chillin
(THE FOLLOWING HAPPENS IN THE VOID FUNCTION)
Here are your words in alphabetical order
awesome
bogus
chillin