66 909
Assignments Done
99,1%
Successfully Done
In October 2018

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);
}
}
}
Expert's answer
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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions