课堂-字符串加密
//字符串加密
//Qi Ming Liu,October 23,2015 package Demo; import javax.swing.JOptionPane;
public class StringSercet {
public static void main(String[] args) {
String str=JOptionPane.showInputDialog("请输入一个字符串:");
char charArray[]=str.toCharArray(); //字符串转化为字符数组
for (int i=0;i<charArray.length;i++) {
if (charArray[i]=='X'||charArray[i]=='Y'||charArray[i]=='Z' )
charArray[i]=(char)(charArray[i]-23);
else charArray[i]=(char)(charArray[i]+3);
}
JOptionPane.showMessageDialog(null,"加密后的字符串:"+String.valueOf(charArray));
}
}