daily pastebin goal
19%
SHARE
TWEET

Untitled

a guest Jan 19th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.*;
  2. import java.util.*;
  3. public class MorseCode
  4. {
  5.     public static String[] getChart() throws IOException
  6.     {  
  7.         int i = 0;
  8.         String[] chart = new String[72];
  9.         File fileName = new File("morsecode.txt");
  10.         Scanner inFile = new Scanner(fileName);
  11.        
  12.         while(inFile.hasNext())
  13.         {
  14.             chart[i] = inFile.next();
  15.             i++;
  16.         }
  17.         inFile.close();
  18.         return chart;
  19.     }
  20.    
  21.     public static String toCode(String m, String[] chart)
  22.     {
  23.         String message = m;
  24.         message = message.toLowerCase();
  25.         message = message.replace(" ", "\n");
  26.         for(int i = 0; i<72; i+=2)
  27.         {
  28.             message = message.replace(chart[i], (chart[i+1] +" "));
  29.         }
  30.         return message;
  31.     }
  32. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top