Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit09765b8

Browse files
authored
Incorporate the class Upper from string package (TheAlgorithms#1952)
1 parent8eb27d7 commit09765b8

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
packagecom.string;
2+
3+
publicclassUpper {
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+
publicstaticStringtoUpperCase(Strings) {
12+
char[]values =s.toCharArray();
13+
for (inti =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+
returnnewString(values);
19+
}
20+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
packagecom.string;
2+
3+
importorg.junit.jupiter.api.Assertions;
4+
importorg.junit.jupiter.api.Test;
5+
6+
classUpperTestextendsUpper {
7+
8+
@Test
9+
voidtestUpper() {
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)

[8]ページ先頭

©2009-2025 Movatter.jp