File tree 3 files changed +55
-13
lines changed
main/java/com/yitianyigexiangfa/pythonchallenge
test/java/com/yitianyigexiangfa/pythonchallenge
3 files changed +55
-13
lines changed Original file line number Diff line number Diff line change 4
4
xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
5
5
<modelVersion >4.0.0</modelVersion >
6
6
<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 >
7
19
8
20
<groupId >org.example</groupId >
9
21
<artifactId >pythonchallenge</artifactId >
Original file line number Diff line number Diff line change 3
3
public class Level2 {
4
4
5
5
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 );
14
11
}
15
12
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
+ }
16
32
17
33
18
34
private static String str = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq " +
Original file line number Diff line number Diff line change 7
7
public class Level2Test {
8
8
9
9
@ 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 );
15
19
}
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
+
16
30
}
You can’t perform that action at this time.
0 commit comments