Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Help with if logic - was JAVA easy

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Help with if logic - was JAVA easy

    So I cant seem to remember how to do this so hopoe fully someone on here will
    import java.io.*;
    import java.util.*;
    public class relearn{
    public static void main( String args[] )
    {
    Scanner kbReader = new Scanner(System.in);
     
    System.out.println("Enter the nucleotide sequence below: "); //Enter One Two
    String AA = kbReader.nextLine( ); 
    int AL = AA.length();
    int x;
     
    for( x=0; x<AL; x++){
    if(AA.equals("a")||AA.equals("A")){
    	System.out.print("U");
    }
    else if(AA.equalsIgnoreCase("T")){
    	System.out.print("A");
    }
    else if(AA.equalsIgnoreCase("C")){
    	System.out.print("G");
    }
    else if(AA.equalsIgnoreCase("G")){
    	System.out.print("C");
    }
     
    }
     
    }
    }

    heres my code what I need it to do is when ever I put in " ATCGTC" I need it to output "UAGCAG" but when I type in more that one letter is just ends the program


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default re: Help with if logic - was JAVA easy

    Those are strange and confusing variable names. Which variable holds the user's input? One with a name like: usersInput would make the code easier to read.

    If the purpose of the code is to look at the letters the user has typed in one at a time, the String class has some methods for getting the letters one at a time so that they can be compared to single letters or characters. Look at the API doc for the String class for methods that will get a sub part of the String or that will get one char at a time.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default re: Help with if logic - was JAVA easy

    Quote Originally Posted by Norm View Post
    Those are strange and confusing variable names. Which variable holds the user's input? One with a name like: usersInput would make the code easier to read.

    If the purpose of the code is to look at the letters the user has typed in one at a time, the String class has some methods for getting the letters one at a time so that they can be compared to single letters or characters. Look at the API doc for the String class for methods that will get a sub part of the String or that will get one char at a time.
    I didn't realy go into much back story but its for coding out DNA strands. My bio teacher challenged me to it but ive forgotten java, but he asked me to make a program that would code out Amino Acids ( String AA) and convert them to mRNA. String AA stores the data then int AL (Acid length) takes the length of AA so if the enter 50 letters 50 should be converted

  4. #4
    Junior Member
    Join Date
    Jan 2014
    Posts
    23
    My Mood
    Mellow
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default re: Help with if logic - was JAVA easy

    Quote Originally Posted by nickerb2k View Post
    So I cant seem to remember how to do this so hopoe fully someone on here will
    import java.io.*;
    import java.util.*;
    public class relearn{
    public static void main( String args[] )
    {
    Scanner kbReader = new Scanner(System.in);
     
    System.out.println("Enter the nucleotide sequence below: "); //Enter One Two
    String AA = kbReader.nextLine( ); 
    int AL = AA.length();
    int x;
     
    for( x=0; x<AL; x++){
    if(AA.equals("a")||AA.equals("A")){
    	System.out.print("U");
    }
    else if(AA.equalsIgnoreCase("T")){
    	System.out.print("A");
    }
    else if(AA.equalsIgnoreCase("C")){
    	System.out.print("G");
    }
    else if(AA.equalsIgnoreCase("G")){
    	System.out.print("C");
    }
     
    }
     
    }
    }

    heres my code what I need it to do is when ever I put in " ATCGTC" I need it to output "UAGCAG" but when I type in more that one letter is just ends the program
    This is not the proper logic ..
    please think differently..
    insted of checking char with the string ..
    make that string to char array and then check each char.
    make use of toCharArray().

Similar Threads

  1. Java Logic
    By JoshKesner in forum Java Theory & Questions
    Replies: 6
    Last Post: November 7th, 2012, 04:26 PM
  2. Java (Easy)
    By ErrorBuster in forum The Cafe
    Replies: 4
    Last Post: May 1st, 2012, 05:17 PM
  3. this is easy for those who know java!!
    By speaker in forum What's Wrong With My Code?
    Replies: 10
    Last Post: March 28th, 2012, 10:04 AM
  4. Help with java logic
    By dever in forum What's Wrong With My Code?
    Replies: 7
    Last Post: February 7th, 2011, 08:41 AM
  5. java Logic Random with out repetition
    By Jhovarie in forum Loops & Control Statements
    Replies: 1
    Last Post: January 13th, 2011, 03:25 PM

Tags for this Thread