2021-09-26 17:26:59 +08:00
|
|
|
package Strings;
|
2020-08-27 00:01:50 +08:00
|
|
|
|
|
|
|
public class Upper {
|
|
|
|
|
2020-10-24 18:23:28 +08:00
|
|
|
/** Driver Code */
|
|
|
|
public static void main(String[] args) {
|
|
|
|
String[] strings = {"ABC", "ABC123", "abcABC", "abc123ABC"};
|
|
|
|
for (String s : strings) {
|
|
|
|
assert toUpperCase(s).equals(s.toUpperCase());
|
2020-08-27 00:01:50 +08:00
|
|
|
}
|
2020-10-24 18:23:28 +08:00
|
|
|
}
|
2020-08-27 00:01:50 +08:00
|
|
|
|
2020-10-24 18:23:28 +08:00
|
|
|
/**
|
|
|
|
* Converts all of the characters in this {@code String} to upper case
|
|
|
|
*
|
|
|
|
* @param s the string to convert
|
|
|
|
* @return the {@code String}, converted to uppercase.
|
|
|
|
*/
|
|
|
|
public static String toUpperCase(String s) {
|
|
|
|
char[] values = s.toCharArray();
|
|
|
|
for (int i = 0; i < values.length; ++i) {
|
|
|
|
if (Character.isLetter(values[i]) && Character.isLowerCase(values[i])) {
|
|
|
|
values[i] = Character.toUpperCase(values[i]);
|
|
|
|
}
|
2020-08-27 00:01:50 +08:00
|
|
|
}
|
2020-10-24 18:23:28 +08:00
|
|
|
return new String(values);
|
|
|
|
}
|
2020-08-27 00:01:50 +08:00
|
|
|
}
|