2012-12-16 166 views
-7

我有一項工作要將莫爾斯電碼轉換爲英文,反之亦然。我需要把莫爾斯轉換成英文的幫助,但是我不能使用我還沒有學到的太複雜的東西,因爲那時它是可疑的。我需要幫助將莫爾斯電碼轉換爲英文(JAVA)

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; 

     } 
    } 

這是我的全部

+6

*「我不能使用過於複雜的東西,我還沒有學會,因爲它是可疑的」*哦,那只是*精彩*。 –

+5

爲我做,但讓它看起來像我做到了! –

+0

該代碼有什麼問題? –

回答

4

不是問的人做你的功課,你應該實際在試圖問題一些努力。

什麼我可以提供如下:

  • 在Java中,這是一種風格的東西,但是我們通常不會命名我們的變量或方法開頭大寫字母,看看CamelCase
  • 你應該看英文到莫爾斯電碼是怎麼做的,它遵循類似的邏輯
  • 最後,這是Java String API供您參考

祝你好運。