-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ3.java
More file actions
65 lines (55 loc) · 2.6 KB
/
Copy pathQ3.java
File metadata and controls
65 lines (55 loc) · 2.6 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package WIX1002_1_2019;
import java.sql.SQLOutput;
import java.util.Scanner;
import java.util.Arrays;
public class Q3 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String genome;
while (true){
System.out.print("Enter genome string [quit to stop] : ");
genome = input.next();
if(genome.equals("quit"))
break;
String[] genomeSplit = genome.split("ATG");
//System.out.println(Arrays.toString(genomeSplit));
String extractGenome = "";
boolean genomeFlag = false;
int split = 1;
if(genome.startsWith("ATG"))
split = 0;
for (; split < genomeSplit.length; split++) {
if(genomeSplit[split].contains("TAG")){
extractGenome = genomeSplit[split].substring(0,genomeSplit[split].indexOf("TAG"));
if(extractGenome.length() % 3 == 0 && !extractGenome.isEmpty()) {
if (!(extractGenome.contains("ATG") || extractGenome.contains("TAG") || extractGenome.contains("TAA") || extractGenome.contains("TGA"))) {
System.out.println(extractGenome);
genomeFlag = true;
}
}
}
if(genomeSplit[split].contains("TAA")){
extractGenome = genomeSplit[split].substring(0,genomeSplit[split].indexOf("TAA"));
if(extractGenome.length() % 3 == 0 && !extractGenome.isEmpty()){
if(!(extractGenome.contains("ATG") || extractGenome.contains("TAG") || extractGenome.contains("TAA") || extractGenome.contains("TGA"))) {
System.out.println(extractGenome);
genomeFlag = true;
}
}
}
if(genomeSplit[split].contains("TGA")){
extractGenome = genomeSplit[split].substring(0,genomeSplit[split].indexOf("TGA"));
if(extractGenome.length() % 3 == 0 && !extractGenome.isEmpty()){
if(!(extractGenome.contains("ATG") || extractGenome.contains("TAG") || extractGenome.contains("TAA") || extractGenome.contains("TGA"))) {
System.out.println(extractGenome);
genomeFlag = true;
}
}
}
}
if(!genomeFlag){
System.out.println("No gene is found");
}
}
}
}