File tree Expand file tree Collapse file tree 3 files changed +55
-13
lines changed
main/java/com/yitianyigexiangfa/pythonchallenge
test/java/com/yitianyigexiangfa/pythonchallenge Expand file tree Collapse file tree 3 files changed +55
-13
lines changed Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 33public 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 " +
Original file line number Diff line number Diff line change 77public 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}
You can’t perform that action at this time.
0 commit comments