Search⌘ K

Solution Review: Playing With Strings

Explore how to write Java methods that process strings by checking their length and conditionally converting them to upper or lower case. Understand how to use methods like length(), apply conditional logic, and return appropriate values based on input, reinforcing your method usage skills in Java programming.

Solution: To be upper case or not to be? #

Java
class challenge_four {
public static String test(String x) {
if (x.length() % 2 == 0) {
return x.toUpperCase();
}
return x.toLowerCase();
}
public static void main( String args[] ) {
String odd = "Hello";
String even = "John";
System.out.println( "Hello:" + test(odd));
System.out.println( "John:" + test(even));
}
}

Understanding the code

...