JAVA算法提高 9-3摩尔斯电码

import java.util.Scanner;

public class Main {


public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String st = in.nextLine();
String st1 = "", st2 = "";


for (int i = 0; i <=st.length(); i++) {
// ||i==st.length()
if (i==st.length()||st.substring(i, i + 1).equals("|")) {
switch (st1) {
case "*-":
st2 = st2 + "A";
break;
case "*":
st2 = st2 + "E";
break;
case "**":
st2 = st2 + "I";
break;
case "--":
st2 = st2 + "M";
break;
case "--*-":
st2 = st2 + "Q";
break;
case "**-":
st2 = st2 + "U";
break;
case "-*--":
st2 = st2 + "Y";
break;
case "-***":
st2 = st2 + "B";
break;
case "**-*":
st2 = st2 + "F";
break;
case "*---":
st2 = st2 + "J";
break;
case "-*":
st2 = st2 + "N";
break;
case "*-*":
st2 = st2 + "R";
break;
case "***-":
st2 = st2 + "V";
break;
case "--**":
st2 = st2 + "Z";
break;
case "-*-*":
st2 = st2 + "C";
break;
case "--*":
st2 = st2 + "G";
break;
case "-*-":
st2 = st2 + "K";
break;

case "---":
st2 = st2 + "O";
break;

case "***":
st2 = st2 + "S";
break;
case "*--":
st2 = st2 + "W";
break;
case "-**":
st2 = st2 + "D";
break;
case "****":
st2 = st2 + "H";
break;
case "*-**":
st2 = st2 + "L";
break;
case "*--*":
st2 = st2 + "P";
break;
case "-":
st2 = st2 + "T";
break;
case "-**-":
st2 = st2 + "X";
break;
default:
break;
}
st1="";
} else  {
st1 = st1 + st.substring(i, i + 1);
}
}
System.out.println(st2.toLowerCase());
}
}

你可能感兴趣的:(JAVA)