私は、英語をモールス符号に、またはその逆に変換する翻訳者に取り組んでいます。コードを書いてコンパイルできましたが、変換したい文を入力した後、コマンドプロンプトのダッシュが次の行に進んで何も出てきません。私のコードに問題がありますか?
これは私のコードです:(私はまだJavaに慣れていないため、最も効率的ではないため、ヒントもいただければ幸いです)
import javax.swing.JOptionPane;
public class translator {
public static void main ( String [] args ) {
String s1 = "Morse";
//Decide whether Morse code or English
String decide = JOptionPane.showInputDialog("Enter 'English' for Morse to English code translation and 'Morse' for English to Morse code translation.Pay attention to Caps.");
//Enter String
String phrasep = JOptionPane.showInputDialog("Enter the words you wish to translate.");
if ( decide.equals( s1 ))
toMorse( phrasep );
else
toEnglish( phrasep );
}
// Translate to Morse
public static void toMorse( String phrase1 )
{
char[] english = new char[36];
char[] number = { 1 };
for ( int i = 65, j = 0; i < 91; i++, j++)
{
english[j] = (char)i;
}
english[26] = 1;
english[27] = 2;
english[28] = 3;
english[29] = 4;
english[30] = 5;
english[31] = 6;
english[32] = 7;
english[33] = 8;
english[34] = 9;
english[35] = 0;
String[] morse = new String[36];
morse[0] = " .- ";
morse[1] = " -.. ";
morse[2] = " -.-. ";
morse[3] = " -.. ";
morse[4] = " . ";
morse[5] = " ..-. ";
morse[6] = " --. ";
morse[7] = " .... ";
morse[8] = " .. ";
morse[9] = " .--- ";
morse[10] = " -.- ";
morse[11] = " .-.. ";
morse[12] = " -- ";
morse[13] = " -." ;
morse[14] = " --- ";
morse[15] = " .--. ";
morse[16] = " --.- ";
morse[17] = " .-. ";
morse[18] = " ... ";
morse[19] = " - ";
morse[20] = " ..- ";
morse[21] = " ...- ";
morse[22] = " .-- ";
morse[23] = " -..- ";
morse[24] = " -.-- ";
morse[25] = " --.. ";
morse[26] = " .---- ";
morse[27] = " ..--- ";
morse[28] = " ...-- ";
morse[29] = " ....- ";
morse[30] = " ..... ";
morse[31] = " -.... ";
morse[32] = " --... ";
morse[33] = " ---.. ";
morse[34] = " ----. ";
morse[35] = " ----- ";
String phrase = phrase1.replace( "//s+", "|");
String[] translation = new String[phrase1.length()];
for ( int j = 0, t = 0, n = 1; j < phrase.length(); j++)
{
while ( j < phrase.length() )
{
if ( phrase.substring(t, n ).equals ( english[j] ) )
{
translation[t] = morse[j];
t++;
n++;
}
}
}
System.out.println( translation );
}
public static void toEnglish( String phrase)
{
System.out.println( phrase );
}
}