Hey,
Hey, so the little chunk of code im trying to write reads in a text file and stores the 2 columns in an array. The data in the file is:
Code:
A .-
B -...
C -.-.
D -..
E .
F ..-.
G --.
H ....
I ..
J .---
K -.-
L .-..
M --
N -.
O ---
P .--.
Q --.-
R .-.
S ...
T -
U ..-
V ...-
W .--
X -..-
Y -.--
Z --..
1 .---
2 ..---
3 ...--
4 ....-
5 .....
6 -.....
7 --...
8 ---..
9 ----.
0 -----
and here is the code
Code:
import java.io.*;
import java.util.*;
public class test {
public static void main(String[] args) throws IOException{
int index;
File morseData = new File("Morse.dat");
Scanner reader = new Scanner(morseData);
String[] morseCode = new String[36];
String[] morseChar = new String[36];
for(index = 0; index < 36; index++)
{
morseChar[index] = reader.next();
morseCode[index] = reader.next();
}
reader.close();
index = Arrays.binarySearch(morseCode, "-----");
System.out.print(index);
}
}
Now unless im missing something, it should return that "-----" is on the last row so index 35 in the array. However it just returns -1. Ive tested by printing out both arrays out to make sure they properly populated and they did, I'm not sure if im just missing something, any help would be great.