字符串寻找基因 P275 9.35
/**
*
*/
package 基因;
import java.util.*;
/**
* @author Administrator
*
*/
public class lyt {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input=new Scanner(System.in);
String str0="",str1="";int num0=0,num1=0,num2=0,num3=0;
System.out.print("请输入一个字符串:");
str0=input.next();
num2=str0.indexOf("ATG");
if(num2==-1)
System.out.print("no gene is found!!!");
while(str0.indexOf("ATG", num1+2)!=-1)
{
num0=num2;
num2=str0.indexOf("ATG", num0+2);
num3=str0.indexOf("TAA", num0+2);
if(num3!=-1&&(num3<num2||num2==-1))
{
System.out.println(str0.substring(num0+3, num3));
num1=num3;
}
num3=str0.indexOf("TAG", num0+2);
if(num3!=-1&&(num3<num2||num2==-1))
{
System.out.println(str0.substring(num0+3, num3));
num1=num3;
}
num3=str0.indexOf("TGA", num0+2);
if(num3!=-1&&(num3<num2||num2==-1))
{
System.out.println(str0.substring(num0+3, num3));
num1=num3;
}
num0=num1+2;
}//TTATGTTTTAAGGATGGGGCGTTAGTT
}
}