Assignemnt #50: CompareTo() Challenge
Code
/// Name: Kelsey Lieberman
/// Period 5
/// Program Name: CompareToChallenge
/// File Name: CompareToChallenge.java
/// Date Finished: 11/6/2015
public class CompareToChallenge
{
public static void main(String[] args)
{
System.out.print("Comparing \"a\" with \"b\" produces ");
System.out.println("a".compareTo("b"));
System.out.print("Comparing \"a\" with \"c\" produces ");
System.out.println( "a".compareTo("c") );
System.out.print("Comparing \"ad\" with \"cb\" produces ");
System.out.println( "ad".compareTo("cb") );
System.out.print("Comparing \"abbab\" with \"abbab12345\" produces ");
System.out.println( "abbab".compareTo("abbab12345") );
System.out.print("Comparing \"qwerty12345\" with \"asdfgh12345\" produces ");
System.out.println( "qwerty12345".compareTo("asdfgh12345") );
System.out.print("Comparing \"qwerty12345\" with \"qwerty\" produces ");
System.out.println( "qwerty12345".compareTo("qwerty") );
System.out.print("Comparing \"sameletters\" with \"sameletters\" produces ");
System.out.println( "sameletters".compareTo("sameletters") );
System.out.print("Comparing \"equals\" with \"equals\" produces ");
System.out.println( "equals".compareTo("equals") );
System.out.print("Comparing \"1\" with \"3\" produces ");
System.out.println( "1".compareTo("3") );
System.out.print("Comparing \"case\" with \"Case\" produces ");
System.out.println( "case".compareTo("Case") );
System.out.print("Comparing \"zebra\" with \"monkey\" produces ");
System.out.println( "zebra".compareTo("monkey") );
System.out.print("Comparing \"dankmemes\" with \"candy\" produces ");
System.out.println( "dankmemes".compareTo("candy") );
}
}
Picture of the output