7-5 sdut-JAVA-encrypted data
分数 10
全屏浏览
切换布局
作者 马新娟
单位 山东理工大学
You have been hired by a company to write a Java application program that will encrypt data so that it may be transmitted more securely. Your program should declare a variable to store a four-digit integer and assign it a value. Your program should encrypt this sequence as follows: replace each digit by (the sum of that digit plus 7) modulus 10. Then swap the first digit with the third, and swap the second digit with the fourth. Your program should display the encrypted data.
Input Specification:
a four-digit integer.
Output Specification:
display the encrypted data
Sample Input:
1234
Sample Output:
Write the corresponding sample output here. For example:
Encrypted data is: 0189
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
栈限制
8192 KB
import java.util.Scanner; public class Main { public static void main(String [] args) { Scanner in =new Scanner(System.in); int n,d1,d2,d3,d4; n = in.nextInt(); String r; d4=n%10; d3=n/10%10; d2=n/100%10; d1=n/1000; d4=(d4+7)%10; d3=(d3+7)%10; d2=(d2+7)%10; d1=(d1+7)%10; r=("Encrypted data is: "+d3+d4+d1+d2); System.out.println(r); } }