Assignemnt #50 and compareTo()
Code
///Name: Mark Katz
///Period: 6
///Program Name: CompareTo() Challenge
///File Name: compare.java
///Date Finished: 10/14/15
public class compare
{
public static void main(String[] args)
{
//greater than 0
System.out.print( "Comparing 'nick' to 'ben' produces " );
System.out.println( "nick".compareTo("ben"));
System.out.println( "" );
System.out.print( "Comparing 'nick' to 'jj' produces " );
System.out.println( "nick".compareTo("jj"));
System.out.println( "" );
System.out.print( "Comparing 'pete' to 'nick' produces " );
System.out.println( "pete".compareTo("nick"));
System.out.println( "" );
System.out.print( "Comparing 'jj' to 'ben' produces " );
System.out.println( "jj".compareTo("ben"));
System.out.println( "" );
System.out.print( "Comparing 'patrick' to 'nick' produces " );
System.out.println( "patrick".compareTo("nick"));
System.out.println( "" );
//less than 0
System.out.print( "Comparing 'ben' to 'mark' produces " );
System.out.println( "ben".compareTo("mark"));
System.out.println( "" );
System.out.print( "Comparing 'mark' to 'nick' produces " );
System.out.println( "mark".compareTo("nick"));
System.out.println( "" );
System.out.print( "Comparing 'ben' to 'patrick' produces " );
System.out.println( "ben".compareTo("patrick"));
System.out.println( "" );
System.out.print( "Comparing 'jj' to 'patrick' produces " );
System.out.println( "jj".compareTo("patrick"));
System.out.println( "" );
System.out.print( "Comparing 'jj' to 'mark' produces " );
System.out.println( "jj".compareTo("mark"));
System.out.println( "" );
//equal to 0
System.out.print( "Comparing 'mark' to 'mark' produces " );
System.out.println( "mark".compareTo("mark"));
System.out.println( "" );
System.out.print( "Comparing 'jj' to 'jj' produces " );
System.out.println( "jj".compareTo("jj"));
}
}
Picture of the output