Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Using java to do digital encryption, the idea is as follows: enter a four-digit number, and each number is added. 1~9 stands for a~i in ASC respectively.
Using java to do digital encryption, the idea is as follows: enter a four-digit number, and each number is added. 1~9 stands for a~i in ASC respectively.
Import java.util.scanner;

Public class Encpryt {

Public encryption () {

Scanner scan = new scanner (system. in);

System.out.println ("Enter four digits:");

string str = scan . next();

while(str! = "q"){

if (str.length()! =4) {

System.out.println ("The number you entered is not 4 digits, please re-enter");

str = scan . next();

Continue;

}

System.out.println ("encryption number is:");

char[]ns = new char[4];

for(int I = 0; I<4; i++){

ns[I]= str . charat(I);

system . out . println(ns[I]-' 0 '+' a '- 1);

}

System.out.println ("Enter four digits:");

str = scan . next();

}

}

/* * * * @ param args

*/

Public static void main(String[] args) {

new Encpryt();

}

}