Assignment #50 and compareTo() Challenge
Code
/// Name: Ali Kurland
/// Period: 6
/// Program Name: CompareTo() Challenge
/// File Name: CompareTo.java
/// Date Finished: 10/5/2015
import java.util.Scanner;
public class CompareTo
{
public static void main( String[] args )
{
System.out.print("Comparing \"cat\" with \"dog\" produces ");
int i = "cat".compareTo("dog");
System.out.println(i);
System.out.print("Comparing \"apple\" with \"orange\" produces ");
int k = "apple".compareTo("orange");
System.out.println(k);
System.out.print("Comparing \"blue\" with \"red\" produces ");
int l = "blue".compareTo("red");
System.out.println(l);
System.out.print("Comparing \"today\" with \"tomorrow\" produces ");
int m = "today".compareTo("tommorow");
System.out.println(m);
System.out.print("Comparing \"left\" with \"right\" produces ");
System.out.println( "left".compareTo("right") );
System.out.println( " " );
System.out.print("Comparing \"up\" with \"down\" produces ");
System.out.println( "up".compareTo("down") );
System.out.print("Comparing \"yes\" with \"no\" produces ");
System.out.println( "yes".compareTo("no") );
System.out.print("Comparing \"pie\" with \"cake\" produces ");
System.out.println( "pie".compareTo("cake") );
System.out.print("Comparing \"train\" with \"boat\" produces ");
System.out.println( "train".compareTo("boat") );
System.out.print("Comparing \"lunch\" with \"breakfast\" produces ");
System.out.println( "lunch".compareTo("breakfast") );
System.out.println( " " );
System.out.print("Comparing \"this\" with \"this\" produces ");
System.out.println( "this".compareTo("this") );
System.out.print("Comparing \"person\" with \"person\" produces ");
System.out.println( "person".compareTo("person") );
}
}
Picture of the output