Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

JAVA help (not trolling) (pls)

Name: Anonymous 2013-04-27 0:35

I'm trying to read in a list of strings of characters A, C, G,and T (ignoring case), and to ignore the rest of the string if it contains any other character.

how do I code this? do I use indexOf?

V new to Java yes. Not trolling just need help quickly.

Name: Anonymous 2013-04-27 0:46



Searching for legit Microsoft Product keys, Windows 8,7,Studio,Server etc.?

 Mail me at jeremiahgoldstein@hotmail.com

 25$ a pop


Searching for legit Microsoft Product keys, Windows 8,7,Studio,Server etc.?

 Mail me at jeremiahgoldstein@hotmail.com

 25$ a pop


Searching for legit Microsoft Product keys, Windows 8,7,Studio,Server etc.?

 Mail me at jeremiahgoldstein@hotmail.com

 25$ a pop

Name: Anonymous 2013-04-27 0:57

Alright, so you need to filter out from the list those strings which have characters other than TGAC? What you do to see if a string is 'good' is to iterate over the indexes of its characters, and see with charAt if one isn't equal any of those characters. In other words

boolean isGood(String str) {
    for (int i = 0; i < str.length(); i++) {
        if ("CGAT".indexOf(str.charAt(i)) < 0) { // look up the return values of indexOf
            return false;
        }
    }
    return true;
}


That just tells you if the string is acceptable, the rest is up to you.

Name: Anonymous 2013-04-27 1:45

>>3
Horrible. That code is kind of like your mom. Slow and ugly.

Name: Anonymous 2013-04-27 2:05

lol
looks like it should return i rather than true/false

Name: Anonymous 2013-04-27 2:09

Written in scala because I don't want more work:


import java.util.regex.Pattern
import java.util.regex.Matcher

def ACGTread(str: String) : String = {
    val p = Pattern.compile("[aAcCgGtT]")
    val m = p.matcher(str)
    var s = ""
    while(m.find()) s += m.group()
    return s
}


How I'd actually do it in scala:


def ACGTread(str: String) : String = str.filter("aAcCgGtT" contains _)

Name: Anonymous 2013-04-27 2:38

Gonna need the official non-jewish Symta version, the one without the fucking english and forced exclamation pointing of the code.

Name: Anonymous 2013-04-27 3:11

>>4
So what? This noob isn't writing performance code or efficient code. He's learning the art of programming.

Name: Anonymous 2013-04-27 6:29

>>1
If you meant "ignore the rest of the string" as in "skip over non ACGT characters then:

(list->string (filter (lambda (c) (memv c '(#\G #\T #\C #\A)))
                      (string->list "AGCTBACT")))


Otherwise, as in "stop cold on the first non-ACGT character" then substitute filter with take-while. Feeding this code to Java is an exercise for the reader.

Name: Anonymous 2013-04-27 6:46

>>1
That post is written by something that is so stupid, if I took its tiny brain and rolled it down the edge of a razor blade, it would be like a lone car going down a six lane highway. Clearly, you spend way too much time in darkened rooms in front of your seven-year-old computer turning a whiter shade of pale. Go outside once in a while and breathe, before your brain starts to rot from all that festering stagnation and cognitive dysfunction.

 Here's a tip: no one will ever know that you've had a lobotomy if you wear a wig to hide to the scars; stop posting your drivel on message boards, and learn to control the slobbering. I understand what you are trying to say, even though you obviously don't. Have you ever noticed that whenever you sit behind a keyboard, some idiot starts typing? To quote Martin Luther King, Jr.: "Nothing in the world is more dangerous than a sincere ignorance and conscientious stupidity."

 You have that certain nothing. Truly, you are about as interesting as watching a slug move slowly across a large rock. You are nastier than a five-dollar whore getting a shit enema. You're a waste of time, space, air, flesh, and the rectum you were born from, retard. Maybe you wouldn't come across as such a jellyfish-sucking mental midget if you weren't an 'idiot savant' without the 'savant' part; if your weren't so fat that when you run, you make the CD player skip at the radio station, or if you didn't have a face so ugly that Peeping Toms break into your house and close the blinds. Who am I kidding? You would.

 Please try to have some small idea of what in the hell you're talking about before you try to post again.

Name: Anonymous 2013-04-27 6:53

Lol, and sed cannot be used because?

Name: Anonymous 2013-04-27 7:46

>>11
Because his class is about teaching him how to churn out enterprise turkey scalable java FactoryFactory generators.

Name: Be Not Dweebs 2013-04-27 8:19

Don't you prog-ramers realize that the original poster (OP) wrote as follows:
"I'm trying to read in a list of strings of characters A, C, G,and T"

Duh! Could it be that he (or she) OP is referring to:
A -- Adenine;
C -- Cytosine;
G -- Guanine;
T -- Thymine? As in
http://en.wikipedia.org/wiki/ACGT
which describes the amino-acid building-blocks of DNA?

Now, does anybuddy know who the people are in this picture:
http://www.flickr.com/photos/jurvetson/8663952985

Name: Anonymous 2013-04-27 9:06

>>13
Sorry, Billy, I'm all out of gold stars.

Name: Anonymous 2013-04-27 9:53

>>13
パチパチパチー

Name: Anonymous 2013-04-27 10:14

>>10
Hi. U MAD?

Name: Anonymous 2013-04-27 11:05

>>8
Eh? The op is already starting to get brain damage by being subjected Java. Adding an additional boolean test only hastens the brain damage. Seriously. With that, here is what I came up with...


http://pastebin.com/KFmt7tnV

Name: Anonymous 2013-04-27 11:12

>>17
That doesn't ignore case or the rest of the string.

Name: Anonymous 2013-04-27 11:15

perl -ne 'print if s/^([acgt]+).*$/\1/i'

Name: Anonymous 2013-04-27 11:18

>>18
I guess the poor wording of the problem threw me off a bit.

Name: Anonymous 2013-04-27 11:29

main = getLine >>= putStrLn . takeWhile (flip elem "AaCcGgTt")

Name: I_Have_A_Hangover 2013-04-27 11:38

>>18
So the OP just wants the letters A, a, C, c, G, g, T, t?  If so, I guess the Java solution would become like...

 http://pastebin.com/ZnQHV8hN

Name: Anonymous 2013-04-27 11:43

>>22
Depends what he means by "ignore the rest of the string". Could be that there's a comment at the end of line.

Name: Anonymous 2013-04-27 12:06

Here OP, all you have to do is convert to equivalent Java code:


int valid(char *str) {
  for(; *str; *str++) {
    switch(*str) {
      case 'a': case 'A':
      case 'c': case 'C':
      case 'g': case 'G':
      case 't': case 'T':
        break;
      default:
        return(0);
    }
  }
 
  return(1);
}

Name: Anonymous 2013-04-27 12:08

>>1
Use a switch statement and a StringBuilder to build the result string -- it's faster.
public class YouSuck {
   
    public static String readACGT(String in) {
        StringBuilder out = new StringBuilder();
        for (int i=0; i < in.length(); i++) {
            char chr = in.charAt(i);
            switch (chr) {
                case 'a': case 'A':
                case 'c': case 'C':
                case 'g': case 'G':
                case 't': case 'T':
                    out.append(chr);
            }
        }
        return out.toString();
    }

    public static void main(String[] args) {
        String test = "aAbCDEgGuUTt";
        System.out.println("Input string: " + test);
        System.out.println("Output string: " + readACGT(test));
    }
}

Name: Anonymous 2013-04-27 14:06

Why are you suddenly answering homework, /prog/?

Name: Anonymous 2013-04-27 14:18

>>26
I just had something similar for my class so I knew the answer XD

Name: Anonymous 2013-04-27 17:02

>>26
Well because any Java programming question basically reduces down to some remedial programming problem. Yup, just add some objects and classes to a simple problem, and watch the newbie programmer get confused!

Name: Anonymous 2013-04-27 17:05

And whoever on here said that having some Java Programming experience doesn't count as real programming experience is 100% correct!

Name: Anonymous 2013-04-27 22:08

>>21
import System.Exit
import System.IO.Error

main :: IO ()
main = act `catchIOError` hdl
  where
    act = getLine >>= putStrLn . takeWhile (flip elem "AaTtCcGg") >> act
    hdl e | isEOFError e = exitWith ExitSuccess | otherwise = ioError e

Name: Anonymous 2013-04-28 21:53



Searching for legit Microsoft Product keys, Windows 8,7,Studio,Server etc.?

 Mail me at jeremiahgoldstein@hotmail.com

 25$ a pop


Searching for legit Microsoft Product keys, Windows 8,7,Studio,Server etc.?

 Mail me at jeremiahgoldstein@hotmail.com

 25$ a pop


Searching for legit Microsoft Product keys, Windows 8,7,Studio,Server etc.?

 Mail me at jeremiahgoldstein@hotmail.com

 25$ a pop

Name: Anonymous 2013-04-28 22:03



Searching for legit Microsoft Product keys, Windows 8,7,Studio,Server etc.?

 Mail me at jeremiahgoldstein@hotmail.com

 25$ a pop


Searching for legit Microsoft Product keys, Windows 8,7,Studio,Server etc.?

 Mail me at jeremiahgoldstein@hotmail.com

 25$ a pop


Searching for legit Microsoft Product keys, Windows 8,7,Studio,Server etc.?

 Mail me at jeremiahgoldstein@hotmail.com

 25$ a pop

Name: Anonymous 2013-04-28 22:09



Searching for legit Microsoft Product keys, Windows 8,7,Studio,Server etc.?

 Mail me at jeremiahgoldstein@hotmail.com

 25$ a pop


Searching for legit Microsoft Product keys, Windows 8,7,Studio,Server etc.?

 Mail me at jeremiahgoldstein@hotmail.com

 25$ a pop


Searching for legit Microsoft Product keys, Windows 8,7,Studio,Server etc.?

 Mail me at jeremiahgoldstein@hotmail.com

 25$ a pop

Name: Anonymous 2013-04-28 22:15



Searching for legit Microsoft Product keys, Windows 8,7,Studio,Server etc.?

 Mail me at jeremiahgoldstein@hotmail.com

 25$ a pop


Searching for legit Microsoft Product keys, Windows 8,7,Studio,Server etc.?

 Mail me at jeremiahgoldstein@hotmail.com

 25$ a pop


Searching for legit Microsoft Product keys, Windows 8,7,Studio,Server etc.?

 Mail me at jeremiahgoldstein@hotmail.com

 25$ a pop

Don't change these.
Name: Email:
Entire Thread Thread List