站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Java 专题将字母翻译成为摩尔码

将字母翻译成为摩尔码

摘要: 将字母翻译成为摩尔码

</td> </tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="240" height="86" align="center" valign="top"> </td> <td width="444" valign="top">
    摩尔码,以前的电报码,也许这个程序没有多大意义,但是可以用来回忆过去的
军事和通讯生活。电报是怎么做出来的呢?呵呵。看了就明白了。
// Name: Fubin My Msn:yonghe169@163.com import java.io.*; import java.util.*; class MorseCoder{ public static void main(String [] args) throws IOException{ BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in)); System.out.println(); System.out.println(); System.out.println("**************************************************"); System.out.println(); System.out.println(" MORSE-CODE CODER "); System.out.println(""); System.out.println(); System.out.println("A Program designed by Ali Ezad Abbas"); System.out.println(" Deptt. of Electrical Engineering, UET, Lahore"); System.out.println(); System.out.println("***************************************************"); System.out.println(); System.out.println(); System.out.print("Please enter the string to be coded (small alphabets): "); String word = stdin.readLine(); StringTokenizer words = new StringTokenizer(word," ",true); String output = ""; String temp = ""; while(words.hasMoreTokens()){ String nerd = words.nextToken(); StringBuffer sos = new StringBuffer(nerd); int len = sos.length(); for(int i=0;i< len;i++){ char input = sos.charAt(i); if(input=='a'){ temp = ".-"; } if(input=='b'){ temp = "-..."; } if(input=='c'){ temp = "-.-."; } if(input=='d'){ temp = "-.."; } if(input=='e'){ temp = "."; }
</td> </tr> <tr> <td height="20" colspan="2">
                if(input=='f'){

                    temp = "..-.";

                }

                    if(input=='g'){

                    temp = "--.";

                }

                    if(input=='h'){

                    temp = "....";

                }

                    if(input=='i'){

                    temp = "..";

                }

                    if(input=='j'){

                    temp = ".---";

                }

                    if(input=='k'){

                    temp = "-.-";

                }

                    if(input=='l'){

                    temp = ".-..";

                }

                    if(input=='m'){

                    temp = "--";

                }

                    if(input=='n'){

                    temp = "-.";

                }

                    if(input=='o'){

                    temp = "---";

                }

                    if(input=='p'){

                    temp = ".--.";

                }

                    if(input=='q'){

                    temp = "--.-";

                }

                    if(input=='r'){

                    temp = ".-.";

                }

                    if(input=='s'){

                    temp = "...";

                }

                    if(input=='t'){

                    temp = "-";

                }

                    if(input=='u'){

                    temp = "..-";

                }

                    if(input=='v'){

                    temp = "...-";

                }

                    if(input=='w'){

                    temp = ".--";

                }

                    if(input=='x'){

                    temp = "-..-";

                }

                    if(input=='y'){

                    temp = "-.--";

                }

                    if(input=='z'){

                    temp = "--..";

                }

                    if(input=='1'){

                    temp = ".----";

                }

                    if(input == '2'){

                    temp = "..---";

                }

                    if(input == '3'){

                    temp = "...--";

                }

                    if(input == '4'){

                    temp = "....-";

                }

                    if(input == '5'){

                    temp = ".....";

                }

                    if(input == '6'){

                    temp = "-....";

                }

                    if(input == '7'){

                    temp = "--...";

                }

                    if(input == '8'){

                    temp = "---..";

                }

                    if(input == '9'){

                    temp = "----.";

                }

                    if(input == '0'){

                    temp = "-----";

                }

                    if(input==' '){

                    temp = "";

                }

                output = output +" "+ temp;

            }

        }

        System.out.println("The coded sentence is: ");

        System.out.println(output);

    }

}

运行结果:
C:\work>java MorseCoder

**********************************************************

MORSE-CODE CODER

A Program designed by Ali Ezad Abbas
Deptt. of Electrical Engineering, UET, Lahore

**********************************************************

Please enter the string to be coded (small alphabets): hello how are you
The coded sentence is:
.... . .-.. .-.. --- .... --- .-- .- .-. . -.-- --- ..-

C:\work>

</td> </tr> </table> </td> </tr> <tr>


↑返回目录
前一篇: 用Base64编码与解码
后一篇: 用Socket发送http请求