Assignment #50: compareTo() Challenge
Code
/// Name: Kiran O'Farrell
/// Program Name: CompareTo() Challenge
/// File Name: CompareToChallenge.java
/// Date Completed: 11/28/15
public class CompareToChallenge {
public static void main (String[] args) {
System.out.print("Comparing \"sky\" with \"stars\" produces ");
int compare1 = "sky".compareTo("stars");
System.out.println(compare1);
System.out.print("Comparing \"moon\" with \"sun\" produces ");
int compare2 = "moon".compareTo("sun");
System.out.println(compare2);
System.out.print("Comparing \"car\" with \"drive\" produces ");
int compare3 = "car".compareTo("drive");
System.out.println(compare3);
System.out.print("Comparing \"land\" with \"ocean\" produces ");
int compare4 = "land".compareTo("ocean");
System.out.println(compare4);
System.out.print("Comparing \"run\" with \"walk\" produces ");
int compare5 = "run".compareTo("walk");
System.out.println(compare5);
System.out.print("Comparing \"word\" with \"word\" produces ");
int compare6 = "word".compareTo("word");
System.out.println(compare6);
System.out.print("Comparing \"string\" with \"string\" produces ");
int compare7 = "string".compareTo("string");
System.out.println(compare7);
System.out.print("Comparing \"same\" with \"same\" produces ");
int compare8 = "same".compareTo("same");
System.out.println(compare8);
System.out.print("Comparing \"compare\" with \"compare\" produces ");
int compare9 = "compare".compareTo("compare");
System.out.println(compare9);
System.out.print("Comparing \"object\" with \"object\" produces ");
int compare10 = "object".compareTo("object");
System.out.println(compare10);
System.out.print("Comparing \"old\" with \"new\" produces ");
int compare11 = "old".compareTo("new");
System.out.println(compare11);
System.out.print("Comparing \"light\" with \"dark\" produces ");
int compare12 = "light".compareTo("dark");
System.out.println(compare12);
System.out.print("Comparing \"war\" with \"peace\" produces ");
int compare13 = "war".compareTo("peace");
System.out.println(compare13);
System.out.print("Comparing \"try\" with \"again\" produces ");
int compare14 = "try".compareTo("again");
System.out.println(compare14);
System.out.print("Comparing \"complete\" with \"assignment\" produces ");
int compare15 = "complete".compareTo("assignment");
System.out.println(compare15);
}
}
Picture of the output