compare two strings in java using command line arguments
Im a java noob. Basically I am trying to create a program that compares
two command line arguments while ignoring case and prints out the lesser
of the two strings. Here is what I have so far:
public class CompareStrings
{
public static void main(String[] args)
{
String s1 = new String(args[0]);
String s2 = new String(args[1]);
if ( s1.compareToIgnoreCase(s2) > 0 )
System.out.println(s2);
else if ( s1.compareToIgnoreCase(s2) < 0 )
System.out.println(s1);
else
System.out.println("Both strings are equal.");
}
}
I keep getting the error "Error: Could not find or load main class
CompareString" when I try to run it. What am I doing wrong?
No comments:
Post a Comment