-8

我有一项任务要做,将莫尔斯电码转换成英语,反之亦然。我需要帮助将莫尔斯语转换成英语,但我不能使用我还没有学过的太复杂的东西,因为那很可疑。

  public class Project11
  {
          public static void main ( String [] args)
      {
                  int a = Input.getInt ("1 for English or 2 for Morse Code");
          String s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890";
          String[] Morse = {".- ","-... ","-.-. ","-.. ",". ","..-. ","--. ",".... ",".. ",".--- ","-.- ",".-.. ","-- ","-. ","--- ",".--. ","--.- ",".-. ",
    "... ","- ","..- ","...- ",".-- ","-..-","-.-- ","--.. ","|",".--- ","..--- ","...-- ","....- ","..... ","-.... ","--... ","---.. ","----. ","----- "}; 
          switch(a)
          {
          case 1:
          English(s1, Morse);
          break;
          case 2:
          Morse(s1, Morse);
          break; 
          default:
          System.out.println("You have typed an incorrect key, please run the program again."); 
          } 
      }
      public static void English (String s1, String[] Morse)
      {
                  String Phrase = Input.getString ("Type in the sentence to convert");
          String convertphrase = Phrase.toUpperCase();
          char[] a = convertphrase.toCharArray();
          char[] s = s1.toCharArray();
          int length = a.length;
          for(int j = 0; j < length; j++)
          {
                           for(int i = 0; i < 35; i++)
               {                                                                 
                                  if(s[i] == a[j])
                  {
                  System.out.print(Morse[i]);   
                  }

               }
          }
      }
      public static void Morse (String s1, String[] Morse)
      {  
          String Phrase = Input.getString ("Type in the sentence to convert");
          char[] a = Phrase.toCharArray();
          int length = a.length;

      }
    } 

这就是我所拥有的

4

1 回答 1

4

与其要求别人做你的功课,你实际上应该在尝试解决问题时表现出一些努力。

我可以提供以下内容:

  • 在 Java 中,这是一种风格的东西,但我们通常不会以大写字母开头命名我们的变量或方法,请查看CamelCase
  • 你应该看看英语到摩尔斯电码是如何完成的,它遵循类似的逻辑
  • 最后,这是供您参考的Java String API

祝你好运。

于 2012-12-16T23:52:07.397 回答