-
Notifications
You must be signed in to change notification settings - Fork 1
/
IP_Morse.java
50 lines (34 loc) · 936 Bytes
/
IP_Morse.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.io.*;
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.Random;
import java.net.URL;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import java.util.Iterator;
import java.util.prefs.Preferences;
import java.util.Hashtable;
import java.awt.*;
public class IP_Morse extends Main {
int n;
public String code_encode(String ip) {
int length = ip.length();
String n[] = {"_____", ".____", "..___", "...__", "...._", ".....", "_....", "__...", "___..", "____.", "..."};
char b[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.'};
String encoded = "";
for (int i=0; i<length; i++) {
for (int j=0; j<11; j++) {
char z = ip.charAt(i);
if (z==b[j]) {
encoded = encoded + n[j];
encoded = encoded + " ";
}
}
}
return encoded;
}
}