Results 1 to 3 of 3
- 11-07-2011, 08:38 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 15
- Rep Power
- 0
While loop is not reading my if statements help please
1 import java.util.Scanner;
2
3 public class DNA {
4
5 public static String GetProteinSeq(String DNA){
6 int BaseCount = 0;
7 int DNALength = DNA.length();
8 String ProteinSeq = "";
9 String BasePairs = "";
10
11 while (BaseCount < DNALength) {
12 BasePairs = DNA.substring(BaseCount, BaseCount+3);
13 //System.out.println(BasePairs); Line shows that its grabbing the base pairs correctly but it does not run it through if statements
14 if (BasePairs=="TAT" || BasePairs =="TTC"){
15 ProteinSeq += 'F';
16 }
17 if (BasePairs=="TTA" || BasePairs=="TTG" || BasePairs==" CTT" || BasePairs=="CTC" || BasePairs=="CTA" || BasePairs=="CTG"){
18 ProteinSeq += "L";
19 }
20 if (BasePairs=="AAT") {
21 ProteinSeq += "J";
22 }
23
24 BaseCount +=3;
25 }
26
27 return ProteinSeq;
28 }
29
30 public static void main (String[]args){
31
32 String normalDNA = "AATTGGAAGCAAATGACATCACAGCAGGTCAGAGAAAAAGGGTTGAGCG GCAGGCACCCAGAGTAGTAG";
33 String mutantDNA = "AATTGGAAGCAAATGACATCACAGCAGGTCAGAGAAAAAGGGTTGAGCG GCAGGCACCCAGAGTAGTAG";
34
35 String ProteinNorm = GetProteinSeq(normalDNA);
36 String ProteinMut = GetProteinSeq(mutantDNA);
37
38 System.out.println(ProteinNorm);
39 System.out.println(ProteinMut);
40
41 }
42
43 }
- 11-07-2011, 08:44 PM #2
Re: While loop is not reading my if statements help please
Don't use == for String comparison. Use the equals() method. This advice has been repeated on this forum and elsewhere on the internet, so I'll let you do a search for more detail.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 11-07-2011, 09:07 PM #3
Member
- Join Date
- Nov 2011
- Posts
- 15
- Rep Power
- 0
Similar Threads
-
Problem with while loop, assigning a variable with a different value every loop? Help
By JavaProg in forum New To JavaReplies: 2Last Post: 11-07-2011, 02:25 AM -
Is it Possible? Array elements Initialized in Loop, can it be viewed outside loop?
By JPH in forum New To JavaReplies: 1Last Post: 10-01-2011, 02:12 AM -
problem with reading excel sheet data reading using poi libraries
By sandeepsai17 in forum New To JavaReplies: 5Last Post: 08-21-2009, 11:03 AM -
Infinite loop when reading text file
By MartinMorrison in forum New To JavaReplies: 2Last Post: 08-03-2009, 04:36 PM -
Loop System print or println statements
By Singing Boyo in forum New To JavaReplies: 6Last Post: 03-22-2009, 03:52 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks