I am writing a program calculate the probability of amino acid code in the given sequence. When i try to get the input from the user, it shows the following error
我正在编写一个程序来计算给定序列中氨基酸代码的概率。当我尝试从用户获取输入时,它显示以下错误
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 407
at java.lang.String.charAt(String.java:646)
at BNC.Sequence.<init>(Sequence.java:50)
at BNC.Navie_Bayesian_Classifier.main(Navie_Bayesian_Classifier.java:34)
407Java Result: 1
My code is
我的代码是
try(Scanner scan=new Scanner(new File("F:\\Thiyaga\\ProteinSequence\\Test.txt")))
{
line = scan.nextLine().trim();
length=line.length();
// line=reader.readLine();
}
System.out.print(length);
for(i=0;i<20;i++)
{
count[i]=0;
probility[i]='\0';
}
for(int k=0;k<length;k++)
{
switch(line.charAt(k))
{
its shows error in at switch or at length
它在开关或长度时显示错误
My input is of this form
我的输入是这种形式
MVKETKFYDILGVPVTATDVEIKKAYRKCALKYHPDKNPSEEAAEKFKEASAAYEILSDPEKRDIYDQFGEDGLSGAGGAGGFPGGGFGFGDDIFSQFFGAGGAQRPRGPQRGKDIKHEISASLEELYKGRTAKLALNKQILCKECEGRGGKKGAVKKCTSCNGQGIKFVTRQMGPMIQRFQTECDCHGTGDIIDPKDRCKSCNGKKVENERILEVHVEPGMKDGQRIVFKGEADQAPDVIPGDVVFIVSERPHKSFKRDGDDLVYEAEIDLLTAIAGGEFALEHVSGDWLKVGIVPGEVIAPGMRKVIEGKGMPIPKYGGYGNLIIKFTIKFPENHFTSEENLKKLEEILPPRIVPAIPKKATVDECVLADFDPAKYNRTRASRGGANYDSDEEEQGGEGVQCASQ
1 个解决方案
#1
The execution of the presented code does not result in an error. Here is a reduced version of the given code snippet, that works very well with the given input file:
执行所呈现的代码不会导致错误。这是给定代码片段的简化版本,与给定的输入文件非常兼容:
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
public class XXX{
public static void main(String[] args){
try(Scanner scan=new Scanner(new File("Test.txt"))){
String line = scan.nextLine().trim();
int length=line.length();
for(int k=0;k<length;k++)
System.out.println(k + " " + line.charAt(k));
} catch (IOException e){
e.printStackTrace();
}
}
}
#1
The execution of the presented code does not result in an error. Here is a reduced version of the given code snippet, that works very well with the given input file:
执行所呈现的代码不会导致错误。这是给定代码片段的简化版本,与给定的输入文件非常兼容:
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
public class XXX{
public static void main(String[] args){
try(Scanner scan=new Scanner(new File("Test.txt"))){
String line = scan.nextLine().trim();
int length=line.length();
for(int k=0;k<length;k++)
System.out.println(k + " " + line.charAt(k));
} catch (IOException e){
e.printStackTrace();
}
}
}