题解 | #字符串加解密#
密码截取
http://www.nowcoder.com/practice/3cd4621963e8454594f00199f4536bb1
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNextLine()) {
encodingsss(sc.nextLine());
// for(int i = 0; i < raws.length; i++) {
// System.out.print(raws[i]);
// }
System.out.println();
// char[] a = encodeStr.toCharArray();
decoding(sc.nextLine());
// for(int i = 0; i < a.length; i++) {
// System.out.print(a[i]);
// }
System.out.println();
}
}
public static void encodingsss(String raws) {
char[] raw = raws.toCharArray();
for(int i = 0; i < raw.length; i++) {
if(raw[i] >= 'a' && raw[i] < 'z') {
raw[i] -= 31;
}
else if(raw[i] == 'z') {
raw[i] = 'A';
}
else if(raw[i] >= 'A' && raw[i] < 'Z') {
raw[i] += 33;
}
else if(raw[i] == 'Z') {
raw[i] = 'a';
}
else if(raw[i] >= '0' && raw[i] < '9') {
raw[i] += 1;
}
else if(raw[i] == '9') {
raw[i] = '0';
}
System.out.print(raw[i]);
}
}
public static void decoding(String raws) {
char[] raw = raws.toCharArray();
for(int i = 0; i < raw.length; i++) {
if(raw[i] > 'a' && raw[i] <= 'z') {
raw[i] -= 33;
}
else if(raw[i] == 'a') {
raw[i] = 'Z';
}
else if(raw[i] >'A' && raw[i] <='Z') {
raw[i] += 31;
}
else if(raw[i] == 'A') {
raw[i] = 'z';
}
else if(raw[i] > '0' && raw[i] <= '9') {
raw[i] -= 1;
}
else if(raw[i] == '0') {
raw[i] = '9';
}
System.out.print(raw[i]);
}
}
}