Results 1 to 3 of 3
  1. #1
    Jtrtoday is offline Member
    Join Date
    Nov 2011
    Posts
    15
    Rep Power
    0

    Default 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 }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default 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!

  3. #3
    Jtrtoday is offline Member
    Join Date
    Nov 2011
    Posts
    15
    Rep Power
    0

    Default Re: While loop is not reading my if statements help please

    Thank you so much helped a bunch!!

Similar Threads

  1. Replies: 2
    Last Post: 11-07-2011, 03:25 AM
  2. Replies: 1
    Last Post: 10-01-2011, 03:12 AM
  3. Replies: 5
    Last Post: 08-21-2009, 12:03 PM
  4. Infinite loop when reading text file
    By MartinMorrison in forum New To Java
    Replies: 2
    Last Post: 08-03-2009, 05:36 PM
  5. Loop System print or println statements
    By Singing Boyo in forum New To Java
    Replies: 6
    Last Post: 03-22-2009, 04:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •