Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class MorseCode
- {
- public static String[] getChart() throws IOException
- {
- int i = 0;
- String[] chart = new String[72];
- File fileName = new File("morsecode.txt");
- Scanner inFile = new Scanner(fileName);
- while(inFile.hasNext())
- {
- chart[i] = inFile.next();
- i++;
- }
- inFile.close();
- return chart;
- }
- public static String toCode(String m, String[] chart)
- {
- String message = m;
- message = message.toLowerCase();
- message = message.replace(" ", "\n");
- for(int i = 0; i<72; i+=2)
- {
- message = message.replace(chart[i], (chart[i+1] +" "));
- }
- return message;
- }
- }
Add Comment
Please, Sign In to add comment