i have written a program to convert character a,g,t,c from a textbox to another value the problem is that when several values apart from a,g,t,c it displays an error message for each invalid character.how can i do it such that on the first invalid character it sees it stop the conversion method.Below are my codes.Thank you
private void dna2rna() {
String DNA = dna_ta.getText();
char[]readdna;
readdna=DNA.toCharArray();
for (int x=0;x<readdna.length;x++){
switch(DNA.charAt(x))
{
case 'A': readdna[x] = 'U';break;
case 'T': readdna[x] = 'A';break;
case 'C': readdna[x] = 'G';break;
case 'G': readdna[x] = 'C';break;
case 'a': readdna[x] = 'u';break;
case 't': readdna[x] = 'a';break;
case 'c': readdna[x] = 'g';break;
case 'g':readdna[x] = 'c';break;
default:
JOptionPane.showMessageDialog(frame,
"Not a DNA Sequence.Please Retry",
"Sequence error",
JOptionPane.ERROR_MESSAGE);
dna_ta.setText("");
rna_ta.setText("");
break;
}
String rna= new String(readdna);
rna_ta.setText(rna);
}
}
the problem is if it finds the the default case it goes out and continue the for loop .how to prevent it from going through the for loop.