OnJava8-Examples/validating/Inverter2.java

20 lines
564 B
Java
Raw Normal View History

2016-08-29 07:27:53 -06:00
// validating/Inverter2.java
2020-10-07 13:35:40 -06:00
// (c)2020 MindView LLC: see Copyright.txt
2016-08-19 08:21:09 -06:00
// We make no guarantees that this code is fit for any purpose.
2016-09-23 13:23:35 -06:00
// Visit http://OnJava8.com for more book information.
2016-08-29 07:27:53 -06:00
package validating;
2016-08-19 08:21:09 -06:00
import static java.lang.Character.*;
2016-08-29 07:27:53 -06:00
public class Inverter2 implements StringInverter {
2016-08-19 08:21:09 -06:00
public String invert(String str) {
String result = "";
for(int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
result += isUpperCase(c) ?
toLowerCase(c) :
toUpperCase(c);
}
return result;
}
}