'Putting subsequences in HashMap
I am trying to get my program to print out "(ABC,1) (BCD,1) (CDB,1) (DBC,1)" if I have a .txt file that shows ABCDBCD but the error code states The local variable hentSub may not have been initialized Java(536870963) on my subsequence getSub. Any tips? The reason it states (ABC,1) is because the 1 is a person, and a subseq of their DNA
public static void main(String[] args) throws FileNotFoundException {
Scanner scanner = new Scanner(new File("C:\\Users\\Public\\File1.txt"));
String currentLine, subString;
int subSize = 3;
HashMap<String, subsequence> subSeqHashNy = new HashMap<String, subsequence> ();
subsequence getSub;
int count = 0;
while (scanner.hasNextLine()) {
currentLine = scanner.nextLine();
currentLine = currentLine.trim();
if (currentLine.length() < subSize) {
break;
}
for (int i = 0; i + subSize <= currentLine.length(); i++) {
subString = currentLinje.substring(i, i + subSize);
System.out.print(subString + " ");
for(subsequence sub1: subSeqHashNy.values()) {
if (hetSub == null) {
subSeqHashNy.put(sub1.key(), sub1);
}
else {
int num = getSub.getNum();
sub1.leggTil(num);
subSeqHashNy.put(sub1.key(), sub1);
}
}
}
System.out.print("\n");
}
scanner.close();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|