</pre><pre code_snippet_id="447832" snippet_file_name="blog_20140811_1_4723818" name="code" class="java"><pre name="code" class="java">package java2; //import java.sql.Date; import java.util.Date; import java.text.SimpleDateFormat; public class Secret1 { public static void main(String args[]) { Date nowTime=new Date();//获取当前时间 System.out.println(nowTime); SimpleDateFormat matter1= //SimpleDateFormat来实现日期的格式化 new SimpleDateFormat("'time':yyyy年MM月dd日E HH:mm:ss 烟台时间"); System.out.println(matter1.format(nowTime)); String s="你真棒!挺你!"; char a[]=s.toCharArray();//s的所有字符初始化给a for (int i = 0; i < a.length; i++) { a[i]=(char)(a[i]^'s');//加密(用异或) } String secret=new String(a); System.out.println("密文:"+secret); for (int i = 0; i < a.length; i++) { a[i]=(char)(a[i]^'s');//解密 } String code=new String(a); System.out.println("原文:"+code); } }