Question

Write a function clean(dna) that returns a new DNA string in which every character that is...

Write a function clean(dna) that returns a new DNA string in which every character that is not an A, C, G, or T is replaced with an N. For example, clean('goat') should return the string 'gnat'.

You can assume dna is all lowercase, but don't assume anything about the nature of the wrong characters (e.g. they could even have been accidentally transcribed as numbers).

No importing

Must use for loop

Homework Answers

Answer #1
package dna;

import java.util.Scanner;

public class DNA {

    private static String clean(String DNA) {
        StringBuilder sb = new StringBuilder();//function to replace characters with n
        for (int i = 0; i < DNA.length(); i++) {
            if (DNA.charAt(i) == 'a' || DNA.charAt(i) == 'c' || DNA.charAt(i) == 'g' || DNA.charAt(i) == 't') {
                sb.append(DNA.charAt(i));
            } else {
                sb.append("n");
            }
        }
        return sb.toString();
    }

    public static void main(String[] args) { //main function
        Scanner sc = new Scanner(System.in);
        String dna = sc.nextLine();
        System.out.println("Clean DNA: " + clean(dna));
    }
}

Output:-

Note:- Please comment if you face any problem. :)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a function named "replacement" that takes a string as a parameter and returns an identical...
Write a function named "replacement" that takes a string as a parameter and returns an identical string except with every instance of the character "i" replaced with the character "n python
C++: Write a function that receives a pointer to a character string consisting of only alphabets...
C++: Write a function that receives a pointer to a character string consisting of only alphabets a-z and returns the character with the maximum number of repetitions. If more than one-character repeats same number of times, return the character with smallest alphabetical order. For example, the string “Mississippi” has three repeated characters (i-4, s-4, p-2). Both ‘i’ and ‘s’ repeated 4 times but ‘i’ is alphabetically smaller hence the function should return ‘i’. Do not count repeated blanks, special characters,...
Use C language    bool isupper(char c): This function returns true if the character in c is...
Use C language    bool isupper(char c): This function returns true if the character in c is an uppercase character between A and Z (inclusive). Note that the C standard library function isupper() both accepts and returns an int, not char or bool, but the behavior is equivalent.     void strlower(char str[]): Change all uppercase ASCII characters in the C string str to their lowercase equivalents. For example, A would become a, and G would become g. All other characters in...
1. Write 3n + 1 Sequence String Generator function (1 point) In lab5.py complete the function...
1. Write 3n + 1 Sequence String Generator function (1 point) In lab5.py complete the function sequence that takes one parameter: n, which is the initial value of a sequence of integers. The 3n + 1 sequence starts with an integer, n in this case, wherein each successive integer of the sequence is calculated based on these rules: 1. If the current value of n is odd, then the next number in the sequence is three times the current number...
**please write code with function definition taking in input and use given variable names** for e.g....
**please write code with function definition taking in input and use given variable names** for e.g. List matchNames(List inputNames, List secRecords) Java or Python Please Note:    * The function is expected to return a STRING_ARRAY.      * The function accepts following parameters:      *  1. STRING_ARRAY inputNames      *  2. STRING_ARRAY secRecords      */ Problem Statement Introduction Imagine you are helping the Security Exchange Commission (SEC) respond to anonymous tips. One of the biggest problems the team faces is handling the transcription of the companies reported...
Strings The example program below, with a few notes following, shows how strings work in C++....
Strings The example program below, with a few notes following, shows how strings work in C++. Example 1: #include <iostream> using namespace std; int main() { string s="eggplant"; string t="okra"; cout<<s[2]<<endl; cout<< s.length()<<endl; ​//prints 8 cout<<s.substr(1,4)<<endl; ​//prints ggpl...kind of like a slice, but the second num is the length of the piece cout<<s+t<<endl; //concatenates: prints eggplantokra cout<<s+"a"<<endl; cout<<s.append("a")<<endl; ​//prints eggplanta: see Note 1 below //cout<<s.append(t[1])<<endl; ​//an error; see Note 1 cout<<s.append(t.substr(1,1))<<endl; ​//prints eggplantak; see Note 1 cout<<s.find("gg")<<endl; if (s.find("gg")!=-1) cout<<"found...
Use python language please #One of the early common methods for encrypting text was the #Playfair...
Use python language please #One of the early common methods for encrypting text was the #Playfair cipher. You can read more about the Playfair cipher #here: https://en.wikipedia.org/wiki/Playfair_cipher # #The Playfair cipher starts with a 5x5 matrix of letters, #such as this one: # # D A V I O # Y N E R B # C F G H K # L M P Q S # T U W X Z # #To fit the 26-letter alphabet into...
Actually a HISTORY question: what tactics does Einhard use to portray Charlemagne in "Life of Charlemagne"...
Actually a HISTORY question: what tactics does Einhard use to portray Charlemagne in "Life of Charlemagne" and what tactics does Procipius use to describe Justinian in a positive light in the "Nika Riots"? Ive posted both excerpts. "Life of Charlemagne" Charles the Great, (Charlemagne in French) reigned 768-814 as king of the Franks and the most important ruler of the Carolingian Dynasty, conquering lands in what is now Germany, France, Spain, and Italy. On Christmas Day 800 C.E., Pope Leo...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT