加了两层密,一层莫斯密码,二层拼音九宫格,代码很简单,但是用来和朋友对话还是挺好玩的,还可以以不同的密钥来写
import java.util.Scanner;
public class jiami {
public static void main(String[] args) {
System.out.println("输入拼音:");
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
String[] arr=s.split("");
for (String str: arr) {
switch(str){
case "a":
System.out.print(21);
break;
case "b":
System.out.print(22);
break;
case "c":
System.out.print(23);
break;
case "d":
System.out.print(31);
break;
case "e":
System.out.print(32);
break;
case "f":
System.out.print(33);
break;
case "g":
System.out.print(41);
break;
case "h":
System.out.print(42);
break;
case "i":
System.out.print(43);
break;
case "j":
System.out.print(51);
break;
case "k":
System.out.print(52);
break;
case "l":
System.out.print(53);
break;
case "m":
System.out.print(61);
break;
case "n":
System.out.print(62);
break;
case "o":
System.out.print(63);
break;
case "p":
System.out.print(71);
break;
case "q":
System.out.print(72);
break;
case "r":
System.out.print(73);
break;
case "s":
System.out.print(74);
break;
case "t":
System.out.print(81);
break;
case "u":
System.out.print(82);
break;
case "v":
System.out.print(83);
break;
case "w":
System.out.print(91);
break;
case "x":
System.out.print(92);
break;
case "y":
System.out.print(93);
break;
case "z":
System.out.print(94);
break;
}
}
}
}
import java.util.Scanner;
public class jiami2 {
public static void main(String[] args) {
System.out.println("输入数字:");
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
String[] arr=s.split("");
for (String str : arr) {
switch(str){
case "0":
System.out.print("----- ");
break;
case "1":
System.out.print(".---- ");
break;
case "2":
System.out.print("..--- ");
break;
case "3":
System.out.print("...-- ");
break;
case "4":
System.out.print("....- ");
break;
case "5":
System.out.print("..... ");
break;
case "6":
System.out.print("-.... ");
break;
case "7":
System.out.print("--... ");
break;
case "8":
System.out.print("---.. ");
break;
case "9":
System.out.print("----. ");
break;
}
}
}
}
import java.util.Scanner;
public class jiemi {
public static void main(String[] args) {
System.out.println("输入密码:");
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
String[] arr=s.split(" ");
for (String str : arr) {
switch(str){
case "-----":
System.out.print("0");
break;
case ".----":
System.out.print("1");
break;
case "..---":
System.out.print("2");
break;
case "...--":
System.out.print(3);
break;
case "....-":
System.out.print("4");
break;
case ".....":
System.out.print("5");
break;
case "-....":
System.out.print("6");
break;
case "--...":
System.out.print("7");
break;
case "---..":
System.out.print("8");
break;
case "----.":
System.out.print("9");
break;
default:
System.out.print("错了");
break;
}
}
}
}
import java.util.Scanner;
public class jiemi2 {
public static void main(String[] args) {
System.out.println("输入数字:");
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
for(int i=0;i<s.length()-1;i+=2){
String strs = s.substring(i, i+2);
switch(strs){
case "21":
System.out.print("a");
break;
case "22":
System.out.print("b");
break;
case "23":
System.out.print("c");
break;
case "31":
System.out.print("d");
break;
case "32":
System.out.print("e");
break;
case "33":
System.out.print("f");
break;
case "41":
System.out.print("g");
break;
case "42":
System.out.print("h");
break;
case "43":
System.out.print("i");
break;
case "51":
System.out.print("j");
break;
case "52":
System.out.print("k");
break;
case "53":
System.out.print("l");
break;
case "61":
System.out.print("m");
break;
case "62":
System.out.print("n");
break;
case "63":
System.out.print("o");
break;
case "71":
System.out.print("p");
break;
case "72":
System.out.print("q");
break;
case "73":
System.out.print("r");
break;
case "74":
System.out.print("s");
break;
case "81":
System.out.print("t");
break;
case "82":
System.out.print("u");
break;
case "83":
System.out.print("v");
break;
case "91":
System.out.print("w");
break;
case "92":
System.out.print("x");
break;
case "93":
System.out.print("y");
break;
case "94":
System.out.print("z");
break;
default:
System.out.print("错了");
}
}
}
|
|