l某公司采用公用电话传递数据信息,数据是小于8位的整数,为了确保安全,在传递过程中需要加密,加密规则如下:
•首先将数据倒序;
•然后将每位数字都加上5,再用和除以10的余数代替该数字;
•然后将第一位数字和最后一位数字交换。
l请任意给定一个小于8位的整数,然后把加密后的结果在控制台打印出来。
import java.util.*;
class JiaMi
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("请输入一个小于8位的整数");
int shu=sc.nextInt();
int count=0;
int linshi=shu;
while (linshi!=0)
{
linshi=linshi/10;
count++;
}
System.out.println(count);
int[] shuzu=new int[count];
//倒序
for (int a=0;a<count;a++ )
{
shuzu[a]=shu%10;
shu=shu/10;
}
System.out.print("{");
for (int x=0;x<shuzu.length ;x++ )
{
if (x!=shuzu.length-1)
{
System.out.print(shuzu[x]+",");
}else
{
System.out.print(shuzu[x]+"}");
}
}
//(每位+5)%10
for (int x=0;x<shuzu.length ;x++ )
{
shuzu[x]=(shuzu[x]+5)%10;
}
//首位和末位交换
int temp=shuzu[0];
shuzu[0]=shuzu[count-1];
shuzu[count-1]=temp;
for (int x=0;x<count ;x++ )
{
System.out.print(shuzu[x]);
}
}
}
|
|