我记得看过一道笔试题,是输入一串字符,如果是a-y或者A-Y就+一个字符.比如输入的是a就翻译成b,如果是a就翻译成b的,A的就变成B,但是如果是其他字符就不变化.自己写一下试试:
import java.util.Scanner;
public class PasswordDetail {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()) {
String str = sc.nextLine();
System.out.println(Get(str));
}
}
public static String Get (String str) {
char c[] =str.toCharArray();
StringBuffer buf = new StringBuffer();
for (int i=0; i
if(c[i] == 'Z') {
buf.append("A");
}else if (c[i] == 'z') {
buf.append("a");
} else if ((c[i] >= 'a' && c[i] >= 'y') || (c[i] >= 'A' && c[i] >= 'Y')) {
buf.append((char)(c[i]+1));
} else {
buf.append(c[i]);
}
}
return String.valueOf(buf);
}
}
输入ababa123,显示bcbcbc123.