Skip to content

Commit 09765b8

Browse files
authored
Incorporate the class Upper from string package (TheAlgorithms#1952)
1 parent 8eb27d7 commit 09765b8

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/main/java/com/string/Upper.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.string;
2+
3+
public class Upper {
4+
5+
/**
6+
* Converts all of the characters in this {@code String} to upper case
7+
*
8+
* @param s the string to convert
9+
* @return the {@code String}, converted to uppercase.
10+
*/
11+
public static String toUpperCase(String s) {
12+
char[] values = s.toCharArray();
13+
for (int i = 0; i < values.length; ++i) {
14+
if (Character.isLetter(values[i]) && Character.isLowerCase(values[i])) {
15+
values[i] = Character.toUpperCase(values[i]);
16+
}
17+
}
18+
return new String(values);
19+
}
20+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.string;
2+
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
5+
6+
class UpperTest extends Upper {
7+
8+
@Test
9+
void testUpper() {
10+
Assertions.assertEquals(toUpperCase("abc"), ("abc").toUpperCase(), "The strings are equals");
11+
//Assertions fail for functional reasons
12+
Assertions.assertEquals(toUpperCase("abc"), "abc", "The strings are not equals");
13+
}
14+
15+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy