Saturday, June 8, 2019

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?


Answer




"Error: Could not find or load main class CompareString"




Your error message says you couldn't load class "CompareString", but your code says your class name is CompareStrings.


No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...