Friday, 8 December 2017

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?


class="post-text" itemprop="text">
class="normal">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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...