java程序题:公用电话传递数据加密的一个问题

某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的,加密规则如下:每位数字都加上5,然后用和除以10的余数代替该数字,再将第一位和第四位交换,第二位和第三位交换。  
import java.util.*;
public class lianxi48   {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
int num=0,temp;
do{
   System.out.print("请输入一个4位正整数:");
      num = s.nextInt();
     }while (num<1000||num>9999);
int a[]=new int[4];
a[0] = num/1000; //取千位的数字
a[1] = (num/100)%10; //取百位的数字
a[2] = (num/10)%10; //取十位的数字
a[3] = num%10; //取个位的数字
for(int j=0;j<4;j++)
{
a[j]+=5;
a[j]%=10;
}
for(int j=0;j<=1;j++)
    {
    temp = a[j];
    a[j] = a[3-j];
    a[3-j] =temp;
    }
System.out.print("加密后的数字为:");
for(int j=0;j<4;j++)
System.out.print(a[j]);
}
}

 

推荐阅读:二手雅阁

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值