Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #822

Re: Convert a String to Int: can I use toInt() instead of Integer.parseInt()?

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 2011-07-05 15:47 -0500
Organization .
Message-ID <dss6179oa9vq21vf7tlu6e78bdhqjdm65m@4ax.com> (permalink)
References (1 earlier) <iulrmk$sg9$1@dont-email.me> <k4b6175jsqa1kie5u7b7pjed29td61lkf1@4ax.com> <iuvi8e$m6g$1@dont-email.me> <7an6179km7upsvba40ebe98gmfedg2414k@4ax.com> <iuvqj8$ilj$1@dont-email.me>

Show all headers | View raw


>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. 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.

The assignment did not say we *couldn't* use BigInteger. How would
that have helped? Haven't used it yet.

- Thee Chicago Wolf [MVP]

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

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