Topic
Password is a very important thing in our life, we can not tell the secret of it all depend on it. Wow, haha. The next is to add a set of password on the password, although simple but also safe. Suppose the Yuan son originally a BBS password for zvbo941987, in order to facilitate memory, he through an algorithm to transform this password into YUANzi1987, this password is his name and year of birth, how forget to forget, And can be blatantly placed in a conspicuous place without being known to the real password. He is so transformed, we all know the letter on the phone: 1–1, Abc–2, Def–3, Ghi–4, jkl–5, Mno–6, pqrs–7, Tuv–8 wxyz–9, 0–0, so simple, Yuan Zi will appear in the password of the lowercase letters into corresponding numbers, Numbers and other symbols do not transform, the declaration: there is no space in the password, and the password appears in the upper case in lowercase, then move back one bit, such as: X, the first edge into lowercase, and then move backward one, is not Y, simple bar. Remember, Z moves backwards is a oh.
Input
YUANzi1987
Output
zvbo941987
Effect
Capitalize lowercase and turn backward one bit, lowercase to number, number fixed
Code
Import Java.util.Scanner; Public classMain { Public Static void Main(string[] args) {String s=NewString ();CharC Scannerinch=NewScanner (System.inch); while(inch. Hasnext ()) {s=inch. nextline ();Char[] ch = s.tochararray (); for(intI=0; I<s.length (); i++) {if(ch[i]<' Z '&&ch[i]>=' A ') {ch[i]+=1; Ch[i]=character.tolowercase (Ch[i]); }Else if(ch[i]==' Z ') {ch[i]=' A '; }Else{if(ch[i]>=' A '&&ch[i]<=' C ') {ch[i]=' 2 '; }if(ch[i]>=' d '&&ch[i]<=' F ') {ch[i]=' 3 '; }if(ch[i]>=' G '&&ch[i]<=' I ') {ch[i]=' 4 '; }if(ch[i]>=' J '&&ch[i]<=' l ') {ch[i]=' 5 '; }if(ch[i]>=' m '&&ch[i]<=' O ') {ch[i]=' 6 '; }if(ch[i]>=' P '&&ch[i]<=' s ') {ch[i]=' 7 '; }if(ch[i]>=' t '&&ch[i]<=' V ') {ch[i]=' 8 '; }if(ch[i]>=' W '&&ch[i]<=' Z ') {ch[i]=' 9 '; }}} System. out. println (CH); } }}
Remember
In fact, the problem of water, just start not converted to a character array, directly
if(s.charAt(i)<‘Z‘&&s.charAt(i)>=‘A‘){ char c=s.charAt(i); c+=1; s=s.replace(s.charAt(i),Character.toLowerCase(c));}
To the back of the work, with the Replace method will be the previous uppercase and lowercase to turn into numbers, had to use an array.
OJ Exercise: simple password cracking (Java Case conversion)