例3-1和例3-2
import java.util.*;
public class Example3_1{
public static void main(String args[]){
Scanner reader=new Scanner(System.in);
System.out.println("输入待移位的int型整数:");
int x=reader.nextInt();
System.out.println("输入移位量:");
int n=reader.nextInt();
System.out.println("左移位的结果:"+(x<<n));
System.out.println("右移位的结果:"+(x>>n));
}
}
public class Example3_2{
public static void main(String args[]){
char a[]={'金','木','水','火','土'};
char secret='z';
for(int i=0;i<a.length;i++){
a[i]=(char)(a[i]^secret);
}
System.out.printf("密文:\n");
for(int i=0;i<a.length;i++){
System.out.printf("%3c",a[i]);
}
for(int i=0;i<a.length;i++){
a[i]=(char)(a[i]^secret);
}
System.out.printf("\n原文:\n");
for(int i=0;i<a.length;i++){
System.out.printf("%3c",a[i]);
}
}
}