Skip to content

Instantly share code, notes, and snippets.

@mattmccarthy11
Last active November 4, 2015 02:10
Show Gist options
  • Save mattmccarthy11/b8b5315493fe43efb42c to your computer and use it in GitHub Desktop.
Save mattmccarthy11/b8b5315493fe43efb42c to your computer and use it in GitHub Desktop.
LEXIHELL!!
import cs1.Keyboard;
public class LexiHell {
public static void main(String [] args){
System.out.println("Enter the First String");
String first = Keyboard.readString();
System.out.println("Enter the Second String");
String second = Keyboard.readString();
System.out.println("Enter the Third String");
String third = Keyboard.readString();
System.out.println("Enter the Fourth String");
String fourth = Keyboard.readString();
/*
The return of this method is an int which can be interpreted as follows:
returns < 0 then the String calling the method is lexicographically first (comes first in a dictionary)
returns == 0 then the two strings are lexicographically equivalent
returns > 0 then the parameter passed to the compareTo method is lexicographically first. */
String order1 = null;
String order2 = null;
String order3 = null;
String order4 = null;
//sorting the first string
if(first.compareTo(second)> 0 && first.compareTo(third) > 0 && first.compareTo(fourth) >0){
order1 = first;
}
else if(first.compareTo(second)>0 && first.compareTo(third) <0 && first.compareTo(fourth) <0){
order2 =first;
}
else if(first.compareTo(second)> 0 && first.compareTo(third) >0 && first.compareTo(fourth) >0){
order3 =first;
}
else if (first.compareTo(second)>0 && first.compareTo(third) > 0 && first.compareTo(fourth) >0){
order4 =first;
}
//sorting the second string

if(second.compareTo(first)> 0 && second.compareTo(third) >0 && second.compareTo(fourth) >0)
{order1 = second;}
else if(second.compareTo(first)< 0 && second.compareTo(third) >0 && second.compareTo(fourth) >0)
{order2 =second;}
else if(second.compareTo(first)< 0 && second.compareTo(third) <0 && second.compareTo(fourth) >0)
{order3 =second;}
else if(second.compareTo(first)< 0 && second.compareTo(third) <0 && second.compareTo(fourth) <0)
{order4 =second;}
//sorting the third string

if(third.compareTo(first)> 0 && third.compareTo(second) >0 && third.compareTo(fourth) >0)
{order1 = third;}
else if(third.compareTo(first)< 0 && third.compareTo(second) >0 && third.compareTo(fourth) >0)
{order2 =third ;}
else if(third.compareTo(first)< 0 && third.compareTo(second) <0 && third.compareTo(fourth) >0)
{order3 =third;}
else if(third.compareTo(first)< 0 && third.compareTo(second) <0 && third.compareTo(fourth) <0)
{order4 =third;}
//sorting the fourth string

if(fourth.compareTo(first)> 0 && third.compareTo(second) >0 && third.compareTo(fourth) >0)
{order1 = third;}
else if(fourth.compareTo(first)< 0 && fourth.compareTo(second) >0 && fourth.compareTo(fourth) >0)
{order2 =fourth;}
else if(fourth.compareTo(first)< 0 && fourth.compareTo(second) <0 && fourth.compareTo(fourth) >0)
{order3 =fourth;}
else if(fourth.compareTo(first)< 0 && fourth.compareTo(second) <0 && fourth.compareTo(fourth) <0)
{order4 =fourth;}
System.out.print("The order is as follows: " +order1 +","+order2 +","+order3 +","+order4 );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment