Java学习者论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

手机号码,快捷登录

恭喜Java学习者论坛(https://www.javaxxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,购买链接:点击进入购买VIP会员
JAVA高级面试进阶视频教程Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程

Go语言视频零基础入门到精通

Java架构师3期(课件+源码)

Java开发全终端实战租房项目视频教程

SpringBoot2.X入门到高级使用教程

大数据培训第六期全套视频教程

深度学习(CNN RNN GAN)算法原理

Java亿级流量电商系统视频教程

互联网架构师视频教程

年薪50万Spark2.0从入门到精通

年薪50万!人工智能学习路线教程

年薪50万!大数据从入门到精通学习路线年薪50万!机器学习入门到精通视频教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程 MySQL入门到精通教程
查看: 354|回复: 0

[Java基础知识]将字母翻译成为摩尔码

[复制链接]
  • TA的每日心情
    开心
    2021-3-12 23:18
  • 签到天数: 2 天

    [LV.1]初来乍到

    发表于 2014-10-2 02:11:53 | 显示全部楼层 |阅读模式
    1.     摩尔码,以前的电报码,也许这个程序没有多大意义,但是可以用来回忆过去的
    2. 军事和通讯生活。电报是怎么做出来的呢?呵呵。看了就明白了。

    3. // Name: Fubin  My Msn:yonghe169@163.com
    4. import java.io.*;
    5. import java.util.*;
    6.     class MorseCoder{
    7.         public static void main(String [] args) throws IOException{
    8.         BufferedReader stdin = new BufferedReader
    9.         (new InputStreamReader(System.in));
    10.         System.out.println();
    11.         System.out.println();
    12.         System.out.println("**************************************************");
    13.         System.out.println();
    14.         System.out.println(" MORSE-CODE CODER ");
    15.         System.out.println("");
    16.         System.out.println();
    17.         System.out.println("A Program designed by Ali Ezad Abbas");
    18.         System.out.println(" Deptt. of Electrical Engineering, UET, Lahore");
    19.         System.out.println();
    20.         System.out.println("***************************************************");
    21.         System.out.println();
    22.         System.out.println();
    23.         System.out.print("Please enter the string to be coded (small alphabets): ");
    24.         String word = stdin.readLine();
    25.         StringTokenizer words = new StringTokenizer(word," ",true);
    26.         String output = "";
    27.         String temp = "";
    28.             while(words.hasMoreTokens()){
    29.             String nerd = words.nextToken();
    30.             StringBuffer sos = new StringBuffer(nerd);
    31.             int len = sos.length();
    32.                 for(int i=0;i< len;i++){
    33.                 char input = sos.charAt(i);
    34.                     if(input=="a"){
    35.                     temp = ".-";
    36.                 }
    37.                     if(input=="b"){
    38.                     temp = "-...";
    39.                 }
    40.                     if(input=="c"){
    41.                     temp = "-.-.";
    42.                 }
    43.                     if(input=="d"){
    44.                     temp = "-..";
    45.                 }
    46.                     if(input=="e"){
    47.                     temp = ".";
    48.                 }
    复制代码

      
      
    1.                 if(input=="f"){
    2.                     temp = "..-.";
    3.                 }
    4.                     if(input=="g"){
    5.                     temp = "--.";
    6.                 }
    7.                     if(input=="h"){
    8.                     temp = "....";
    9.                 }
    10.                     if(input=="i"){
    11.                     temp = "..";
    12.                 }
    13.                     if(input=="j"){
    14.                     temp = ".---";
    15.                 }
    16.                     if(input=="k"){
    17.                     temp = "-.-";
    18.                 }
    19.                     if(input=="l"){
    20.                     temp = ".-..";
    21.                 }
    22.                     if(input=="m"){
    23.                     temp = "--";
    24.                 }
    25.                     if(input=="n"){
    26.                     temp = "-.";
    27.                 }
    28.                     if(input=="o"){
    29.                     temp = "---";
    30.                 }
    31.                     if(input=="p"){
    32.                     temp = ".--.";
    33.                 }
    34.                     if(input=="q"){
    35.                     temp = "--.-";
    36.                 }
    37.                     if(input=="r"){
    38.                     temp = ".-.";
    39.                 }
    40.                     if(input=="s"){
    41.                     temp = "...";
    42.                 }
    43.                     if(input=="t"){
    44.                     temp = "-";
    45.                 }
    46.                     if(input=="u"){
    47.                     temp = "..-";
    48.                 }
    49.                     if(input=="v"){
    50.                     temp = "...-";
    51.                 }
    52.                     if(input=="w"){
    53.                     temp = ".--";
    54.                 }
    55.                     if(input=="x"){
    56.                     temp = "-..-";
    57.                 }
    58.                     if(input=="y"){
    59.                     temp = "-.--";
    60.                 }
    61.                     if(input=="z"){
    62.                     temp = "--..";
    63.                 }
    64.                     if(input=="1"){
    65.                     temp = ".----";
    66.                 }
    67.                     if(input == "2"){
    68.                     temp = "..---";
    69.                 }
    70.                     if(input == "3"){
    71.                     temp = "...--";
    72.                 }
    73.                     if(input == "4"){
    74.                     temp = "....-";
    75.                 }
    76.                     if(input == "5"){
    77.                     temp = ".....";
    78.                 }
    79.                     if(input == "6"){
    80.                     temp = "-....";
    81.                 }
    82.                     if(input == "7"){
    83.                     temp = "--...";
    84.                 }
    85.                     if(input == "8"){
    86.                     temp = "---..";
    87.                 }
    88.                     if(input == "9"){
    89.                     temp = "----.";
    90.                 }
    91.                     if(input == "0"){
    92.                     temp = "-----";
    93.                 }
    94.                     if(input==" "){
    95.                     temp = "";
    96.                 }
    97.                 output = output +" "+ temp;
    98.             }
    99.         }
    100.         System.out.println("The coded sentence is: ");
    101.         System.out.println(output);
    102.     }
    103. }
    104. 运行结果:
    105. C:work>java  MorseCoder

    106.                      
    复制代码
    **********************************************************  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>
      
       
         
         
          
          

            
          

            
          
         
       

      


    源码下载:http://file.javaxxz.com/2014/10/2/021152703.zip
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|手机版|Java学习者论坛 ( 声明:本站资料整理自互联网,用于Java学习者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

    GMT+8, 2024-5-20 01:39 , Processed in 0.360712 second(s), 34 queries .

    Powered by Discuz! X3.4

    © 2001-2017 Comsenz Inc.

    快速回复 返回顶部 返回列表