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: Sequences (convert char[] to String) [Replacing String with Character]

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Sequences (convert char[] to String) [Replacing String with Character]

    I am quite a beginner at programming.. was given an assignment and don't understand how to complete the rest of it. I have tried for hours and hours and can't figure it out. I would greatly appreciate the assistance as to I have no clue what I am doing.

    Write a program in Java that stores the following sequence that is comprised of only 'A','C','G', & 'T' characters: [ATGACATCTCTCCATACG]. The program should store the sequence both as a String and as a char[].

    The program should accept two inputs from the user: -A single character with the only allowable values are either 'A','C','G', or 'T', and -An integer value that is greater than 0 and smaller than the length of the sequence.

    Your program should then produce the following as output: -It prints a total count of the occurrences of the single character provided as input.

    -It identifies the locations where the character entered by the user appears in the sequence at a location that is greater than or equal to the integer value provided as input by the user

    -It generates a new list with the character entered by the user replaced by an asterisk ['*'] according to the previous requirement.

    -Your program should provide two sets of methods to implement this functionality: one set dealing with the sequence as a char[] and the other set of methods dealing with the sentence as an instance of String.

    -Your program should do the necessary checking on the values provided for the character and integer inputs to prevent the values provided by the user from getting your program to malfunction.

    -You should provide as output test cases of your program for a user input corresponding to each of the four letters, naely: 'A','C','G', & 'T', and for two integer values: 0 and 4 - for a total of eight test cases.

    __________________________________________________ __________________________________________________ _______
    This is what I have so far, let me know what I need to do! THANKS!!

    package Java;
     
    import static Java.CountEachLetter.countLetters;
    import java.util.regex.*;
    import java.util.*;
    import java.util.Scanner;
     
    public class Sequence {
     
    public static void main(String[] args) {
     
    Scanner input = new Scanner(System.in);
     
    // Prompt the user to enter a string
    System.out.print("Enter a string: ");
    String s = input.nextLine();
     
    // Counts each letter to Lower Case
    int[] counts = countLetters(s.toLowerCase());
     
    // Display results
    for (int i = 0; i < counts.length; i++) {
    if (counts[i] != 0)
    System.out.println((char)('A' + i) + " appears " +
    counts[i] + ((counts[i] == 1) ? " time" : " times"));
    }
    // String result = input.replace("*", "asterisk");
     
    //matching
    String seq = input.nextLine();
    Pattern p = Pattern.compile(""); //"C*A*" //"C*A+"
    Matcher m = p.matcher(seq);
    // boolean res = m.matches();
    // System.out.println("matching CCC " + res);
    System.out.println(m.replaceAll("*"));
     
     
    //replace all ACC with _?
    seq = "CGTATCCCACAGCACCAACATTTTTTCCAACAACCCCA"…
    p = Pattern.compile("AC+A");
    m = p.matcher(seq);
    // System.out.println("replacing all AC+C with _");
    //System.out.println(m.replaceAll("*"));
    System.out.println();
     
    }
    }


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,697
    Thanks
    25
    Thanked 334 Times in 310 Posts

    Default Re: Sequences (convert char[] to String) [Replacing String with Character]

    When asking a question like this, it helps if you also provide (as well as the description you included and your code):
    1. A sample input you have tried
    2. The current output from your sample
    3. The expected output for your sample
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Sequences (convert char[] to String) [Replacing String with Character]

    Okay will try and upload output screenshots later on. About to go to work for tonight.

    The output so far just prints the number of times 'A', 'C', 'G', & 'T' is inputted by the user...
    I need it for the sequence.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,355
    Thanks
    182
    Thanked 833 Times in 776 Posts
    Blog Entries
    5

    Default Re: Sequences (convert char[] to String) [Replacing String with Character]

    This thread has been cross posted here:

    http://www.java-forums.org/new-java/82092-sequences-convert-char-string-replacing-string-character.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting


  5. The Following User Says Thank You to copeg For This Useful Post:

    GregBrannon (September 25th, 2013)

Similar Threads

  1. Replies: 3
    Last Post: March 23rd, 2013, 08:20 PM
  2. How to convert char to string by using method invocation?
    By Akirien in forum Object Oriented Programming
    Replies: 1
    Last Post: August 26th, 2012, 06:49 AM
  3. How to convert or break String into Character
    By Bharath12 in forum Java Theory & Questions
    Replies: 2
    Last Post: September 15th, 2011, 12:41 AM
  4. [SOLVED] String Matcher finding only char not a whole string
    By Kakashi in forum What's Wrong With My Code?
    Replies: 11
    Last Post: February 18th, 2011, 09:58 AM
  5. Convert CHAR to STRING
    By fh84 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: October 29th, 2009, 10:21 PM