-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatches.java
More file actions
32 lines (31 loc) · 872 Bytes
/
Copy pathmatches.java
File metadata and controls
32 lines (31 loc) · 872 Bytes
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
// Program to find the matches and position of matches in the given two seqeunces
class matches
{
public static void main (String args[])
{
String seq1 = args[0];
String seq2 = args[1];
int matches = 0;
int len = (seq1.length() > seq2.length())? seq2.length() : seq1.length();
int [] pos = new int[len];
int pos_i = 0;
char [] matched_n = new char[len];
for (int i = 0; i < len; i++)
{
if (seq1.toCharArray()[i] == seq2.toCharArray()[i])
{
matches++;
matched_n[pos_i] = seq1.toCharArray()[i];
pos[pos_i] = i + 1;
pos_i++;
}
}
System.out.println("Number of Matches : " + Integer.toString(matches));
System.out.print("Positions : ");
for (int i = 0; i < pos_i; i++)
System.out.print(pos[i] + " ");
System.out.print("\n");
System.out.println("Matches : " + String.valueOf(matched_n));
System.out.println();
}
}