Assignment #50
Code
///jack newsom
///period 5
///program name CompareTo
///filename CompareTo.java
///date completed 9/29/15
import java.util.Scanner;
public class CompareTo
{
public static void main( String[] args )
{
System.out.println("This program will use the compareTo() method to compare two strings");
System.out.println("Comparing \"a\" with \"b\" produces ");
int ex1 = "a".compareTo("b");
System.out.println(ex1);
System.out.println("Comparing \"A\" with \"b\" produces ");
int ex2 = "A".compareTo("b");
System.out.println(ex2);
System.out.println("Comparing \"A\" with \"a\" produces ");
int ex3 = "A".compareTo("a");
System.out.println(ex3);
System.out.println("Comparing \"a\" with \"z\" produces ");
int ex4 = "a".compareTo("z");
System.out.println(ex4);
System.out.println("Comparing \"A\" with \"z\" produces ");
int ex5 = "A".compareTo("z");
System.out.println(ex5);
System.out.println("Comparing \"y\" with \"a\" produces ");
int ex6 = "y".compareTo("a");
System.out.println(ex6);
System.out.println("Comparing \"ab\" with \"a\" produces ");
int ex7 = "ab".compareTo("a");
System.out.println(ex7);
System.out.println("Comparing \"ac\" with \"a\" produces ");
int ex8 = "ac".compareTo("a");
System.out.println(ex8);
System.out.println("Comparing \"abc\" with \"a\" produces ");
int ex9 = "abc".compareTo("a");
System.out.println(ex9);
System.out.println("Comparing \"zb\" with \"a\" produces ");
int ex10 = "zb".compareTo("a");
System.out.println(ex10);
System.out.println("Comparing \"ccc\" with \"ccc\" produces ");
int ex11 = "ccc".compareTo("ccc");
System.out.println(ex11);
System.out.println("Comparing \"ddd\" with \"ddd\" produces ");
int ex12 = "ddd".compareTo("ddd");
System.out.println(ex12);
}
}
Picture of the output