我需要帮助将摩尔斯电码转换成英文(JAVA)

时间:2012-12-16 23:41:09

标签: java translate morse-code

我有一项关于将莫尔斯电码转换成英语的任务,反之亦然。我需要帮助将莫尔斯转换成英语,但我不能使用我尚未学到的太复杂的东西,因为那时它是可疑的。

  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;

      }
    } 

这就是我的全部

1 个答案:

答案 0 :(得分:4)

不应该让人们做功课,而应该在尝试解决问题时付出一些努力。

我能提供的是以下内容:

  • 在Java中,它有点像样式,但我们通常不会用大写字母命名我们的变量或方法,请查看CamelCase
  • 您应该看看英语到摩尔斯电码的代码是如何完成的,它遵循类似的逻辑
  • 最后,这是Java String API供您参考
祝你好运。