Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #829
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.glorb.com!news-out.readnews.com!news-xxxfer.readnews.com!s09-10.readnews.com!posts.news.usenetmonster.com!nnrp3-unl.asbnva.usenetmonster.com!not-for-mail |
|---|---|
| From | "Thee Chicago Wolf [MVP]" <.@.> |
| Newsgroups | comp.lang.java.help |
| Subject | Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? |
| Date | Wed, 06 Jul 2011 13:13:20 -0500 |
| Organization | . |
| Reply-To | . |
| Message-ID | <lb9917h7pndcps3u8vif4muoe330n77q1p@4ax.com> (permalink) |
| References | <521s0711i3d7bsc8620isi0oiidl91kujq@4ax.com> <iulrmk$sg9$1@dont-email.me> <k4b6175jsqa1kie5u7b7pjed29td61lkf1@4ax.com> <iuvi8e$m6g$1@dont-email.me> <7an6179km7upsvba40ebe98gmfedg2414k@4ax.com> <iuvqj8$ilj$1@dont-email.me> <dss6179oa9vq21vf7tlu6e78bdhqjdm65m@4ax.com> <97imauF3tbU1@mid.individual.net> |
| X-Newsreader | Forte Agent 6.00/32.1186 |
| X-No-Archive | yes |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| Lines | 81 |
| NNTP-Posting-Host | 3abf70fc.unlimited.usenetmonster.com |
| X-Trace | DXC=bKTJ^8f_T_8;C;mLn7^6i;k\2KDSF=2@2FV0LA4MIjQ;mTIDj6@1Wa<k7[A=hb2n?4:Vo0UhT=lI=a;B]2g4YI2:TA`X]=O@ZU>KhT`B3THi:< |
| X-Complaints-To | killthespammer@usenetmonster.com |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.help:829 |
Show key headers only | View raw
On Wed, 06 Jul 2011 09:57:02 +0100, Nigel Wade <nmw-news@ion.le.ac.uk> wrote: >On 05/07/11 21:47, Thee Chicago Wolf [MVP] wrote: >>> On 7/5/2011 11:57 AM, Thee Chicago Wolf [MVP] wrote: >>>> Realistically, everything is a string until you try >>>> and do a math op on it, right? >>> >>> >>> No, there are very large differences between the internal representation >>> of an integer and the internal representation of a String. >>> >>> At least in Java, you can't do math on Strings. >>> >>> I'm curious now about your programming experience. It matters, at least >>> in part, if you really need help. The part of your post I quoted above >>> is very strange to me, even nonsensical, so I'm asking why you think >>> strings and numbers are somehow equivalent, because they aren't. >>> >>> Also, what exactly is your assignment? Are you allowed to use >>> BigInteger? Have you clarified with your instructor yet? >> >> Sorry if that was confusing. I meant to say that to Java, everything >> is string input until it's assigned a data type. That's what my prof >> says. > >Oh, dear. He sounds like a Python programmer... >It is not true of Java. > >> I don't have any programming experience, this is Programming II. >> And yes, I know you cannot do math on String unless the String is >> totally numeric in which case it first must be converted to integer >> and then have a math op done on it. So when I stated that everything >> is a string until you do a math op on it, I did not mean literally >> that. I understand that data type manipulation has to happen first. >> >> The assignment, exactly, was: >> >> 1. You have a 1000-digit string of numbers. >> 2. Go through that string of numbers and find the 5 consecutive >> numbers whose product is the largest and print that product. >> 3. Print the 5 consecutive numbers that produced the largest product. >> >> So basically it was a matter of 1) loading up an array with the 1000 >> digits by "converting" the String to int using Integer.parseInt() and >> 2) using two for loops--one to load the array and one to do >> multiplication using x[i]*x[i+1]*x[i+2]*x[i+3]*x[i+4] as an algorithm. >> i would obviously increment to go through the array to the end minus 5 >> (to prevent out-of-bounds. i.e., x.length-5). That worked for me. > >That's rather a verbose way of getting things done. You might want to >look at the Javadocs for the String class. Look for methods which return >a substring (in particular one which meets your requirement to extract >any 5 consecutive characters from your 1000 character string). Then look >at the methods of the Integer (or Long) class to find one which can >parse that substring into a number. A simple loop around that, and a >check for a max., ought to get the job done. > >Javadocs are your best friend when learning and/or programming in Java, >and the Java Tutorials will help you with simple worked examples. I >still refer to them on a regular basis. > >Don't catch IDE'itis (where you choose a method based on what pops up in >the IDE completion list). Until you know the methods in detail, look >them up in the Javadocs. > >> >> The assignment did not say we *couldn't* use BigInteger. How would >> that have helped? Haven't used it yet. > >Does it say you have to load the string into an int array? If you don't, >then I wouldn't. As I told one of the other posters, Maybe I just misunderstood my prof when he said it's all strings. I am still learning this stuff. The assignment didn't say it couldn't be used. But, it wasn't something I'd known about anyway so it might not have helped this time around. - Thee Chicago Wolf [MVP]
Back to comp.lang.java.help | Previous | Next — Previous in thread | Next in thread | Find similar
Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-01 12:53 -0500
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Jeff Higgins <jeff@invalid.invalid> - 2011-07-01 17:55 -0400
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? markspace <-@.> - 2011-07-01 18:19 -0700
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-05 10:26 -0500
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-07-05 13:39 -0400
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-05 13:57 -0500
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? markspace <-@.> - 2011-07-05 13:01 -0700
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-05 15:47 -0500
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? markspace <-@.> - 2011-07-05 14:57 -0700
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-06 13:11 -0500
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? markspace <-@.> - 2011-07-06 11:54 -0700
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-06 16:58 -0500
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? markspace <-@.> - 2011-07-06 15:36 -0700
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Patricia Shanahan <pats@acm.org> - 2011-07-06 16:53 -0700
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? markspace <-@.> - 2011-07-06 18:07 -0700
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-07-06 09:57 +0100
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-06 13:13 -0500
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-07-07 09:43 +0100
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Lothar Kimmeringer <news200709@kimmeringer.de> - 2011-07-06 11:15 +0200
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-06 13:14 -0500
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-07-05 16:27 -0400
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Lothar Kimmeringer <news200709@kimmeringer.de> - 2011-07-06 11:22 +0200
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-07-06 07:33 -0400
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-07-01 23:06 -0400
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Patricia Shanahan <pats@acm.org> - 2011-07-01 20:28 -0700
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-05 10:27 -0500
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? Roedy Green <see_website@mindprod.com.invalid> - 2011-07-04 08:59 -0700
Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()? "Thee Chicago Wolf [MVP]" <.@.> - 2011-07-05 10:30 -0500
csiph-web