Skip to content

Commit 0476078

Browse files
level 2
1 parent e7b3af5 commit 0476078

File tree

3 files changed

+55
-13
lines changed

3 files changed

+55
-13
lines changed

pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66
<packaging>jar</packaging>
7+
<build>
8+
<plugins>
9+
<plugin>
10+
<groupId>org.apache.maven.plugins</groupId>
11+
<artifactId>maven-compiler-plugin</artifactId>
12+
<configuration>
13+
<source>8</source>
14+
<target>8</target>
15+
</configuration>
16+
</plugin>
17+
</plugins>
18+
</build>
719

820
<groupId>org.example</groupId>
921
<artifactId>pythonchallenge</artifactId>

src/main/java/com/yitianyigexiangfa/pythonchallenge/Level2.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,32 @@
33
public class Level2 {
44

55
public static void main(String[] args) {
6-
char[] chars = str.toCharArray();
7-
for (char charElment: chars) {
8-
// char newChar = charElment + 2;
9-
System.out.print(Character.toString(charElment));
10-
System.out.println();
11-
int value = Character.getNumericValue(charElment);
12-
System.out.print(value);
13-
}
6+
String result = makeTrans(str);
7+
System.out.println(result);
8+
String urlBase = "map";
9+
String url = makeTrans(urlBase);
10+
System.out.println(url);
1411
}
1512

13+
public static String makeTrans(String base){
14+
byte[] bytes = base.getBytes();
15+
int len = bytes.length;
16+
byte[] bytes2 = new byte[len];
17+
for (int i = 0; i < len; i++) {
18+
byte b = bytes[i];
19+
if(!Character.isAlphabetic(b)){
20+
bytes2[i] = b;
21+
} else if(b == 'y'){
22+
bytes2[i] = (byte)'a';
23+
} else if(b == 'z'){
24+
bytes2[i] = (byte)'b';
25+
}else {
26+
bytes2[i] = (byte) (b + 2);
27+
}
28+
}
29+
String result = new String(bytes2);
30+
return result;
31+
}
1632

1733

1834
private static String str = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq " +

src/test/java/com/yitianyigexiangfa/pythonchallenge/Level2Test.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,24 @@
77
public class Level2Test {
88

99
@Test
10-
public void charToInteger() {
11-
byte[] bytes = "a".getBytes();
12-
int digit = bytes[0];
13-
assertEquals(digit, 97);
14-
System.out.println(digit);
10+
public void isAlphabetic() {
11+
boolean semicolonIsNotAlphabetic = Character.isAlphabetic(';');
12+
assertEquals(false, semicolonIsNotAlphabetic);
13+
boolean aIsAlphabetic = Character.isAlphabetic('a');
14+
assertEquals(true, aIsAlphabetic);
15+
boolean upperCaseAIsAlphabetic = Character.isAlphabetic('Z');
16+
assertEquals(true, upperCaseAIsAlphabetic);
17+
boolean spaceIsNotAlphabetic = Character.isAlphabetic(' ');
18+
assertEquals(false, spaceIsNotAlphabetic);
1519
}
20+
21+
@Test
22+
public void bytesToString() {
23+
String s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
24+
byte[] bytes = s.getBytes();
25+
for (int i = 0; i < bytes.length; i++) {
26+
System.out.println(bytes[i]);
27+
}
28+
}
29+
1630
}

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