例如: s = "ABCBOATER"中包含最长的DNA片段是"AT",所以最长的长度是2。
import java.util.Scanner;
public class findDNA {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str=sc.nextLine();
getDnaNum(str);
}
private static void getDnaNum(String str) {
int tem=1;
int tmp=0;
int len=str.length();
char[] ch= str.toCharArray();
for(int i=0;i<len-1;i++){
if(ch[i]=='A' || ch[i]=='C' || ch[i]=='G'|| ch[i]=='T' ){
if(ch[i+1]=='A' ||ch[i+1]=='C' || ch[i+1]=='G'||ch[i+1]=='T' ){
tem++;
}
if(tem>tmp)
tmp=tem;
}else{
tem=1;
}
}
System.out.println(tmp);
}
}