QwertyManiac
Commander in Chief
A java problem...
heres the code
It gives an error and closes on Enterin the data and pressing ENTER sayin that
Line 27 is
What is the problem here ?
The Syntaxes r all correct...
heres the code
Code:
import java.io.*;
class DNA
{
public static void main(String args[]) throws IOException
{
String A;
char a;
int i,j;
DataInputStream in = new DataInputStream(System.in);
A=in.readLine();
j=A.length();
StringBuffer Str = new StringBuffer(1000);
StringBuffer Str1 = new StringBuffer(1000);
for(i=0;i<=j;i++)
{
a=A.charAt(i);
switch (a)
{
case 'A' :
Str1=Str.insert(i,'T');
case 'T' :
Str1=Str.insert(i,'A');
case 'C' :
Str1=Str.insert(i,'G');
case 'G' :
Str1=Str.insert(i,'C');
case 'B' :
Str1=Str.insert(i,'V');
case 'V' :
Str1=Str.insert(i,'B');
case 'D' :
Str1=Str.insert(i,'H');
case 'H' :
Str1=Str.insert(i,'D');
case 'K' :
Str1=Str.insert(i,'M');
case 'M' :
Str1=Str.insert(i,'K');
case 'Y' :
Str1=Str.insert(i,'R');
case 'R' :
Str1=Str.insert(i,'Y');
case 'S' :
case 'W' :
case 'N' :
default :
System.out.println("The Pair Structure That You Have Entered is Invalid, Please Restart the Program and Enter Again.");
}
}
System.out.println("The DNA Pair You Entered is "+ A);
System.out.println();
System.out.println("The Decoded DNA Pair is "+ Str1);
}
}
It gives an error and closes on Enterin the data and pressing ENTER sayin that
Code:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 2
at java.lang.String.charAt(Unknown Source)
at DNA.main(DNA.java:27)
Line 27 is
Code:
a=A.charAt(i);
What is the problem here ?
The Syntaxes r all correct...