Answer to Question #54111 in Java | JSP | JSF for Nicholas

Question #54111
I have to write a program that accepts two command line string arguments and prints the lesser of them, if case is ignored. The program should look like this when it runs:
$
java Main Zoophyte aardvark
aardvark
$

This is the code I have so far:
public class LeastString {

public static void main (String[] args) {
String s = args[0];
String t = args[1];
System.out.println(s.trim());
System.out.println(t.trim());
System.out.println(s.compareToIgnoreCase(t));
if (s > t) {
System.out.println(s);
} else (s < t){
System.out.println(t);
}
}
}
1
Expert's answer
2015-08-14T02:57:50-0400
public class LeastString {

public static void main(String[] args) {

String s = args[0];
String t = args[1];

System.out.println(s);
System.out.println(t);
System.out.println(s.compareToIgnoreCase(t));

if (s.compareToIgnoreCase(t) < 0) {
System.out.println(s);//print s if it lesser than t
} else if (s.compareToIgnoreCase(t) > 0) {
System.out.println(t);
}


}

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS