Article View: borland.public.jbuilder.java.swing
Article #10395Re: Problems when adding the two numbers 2147483646 and 2 in Jbuilder......WHY...WHY....WHY
From: Rich Wilkman
Date: Tue, 21 Sep 1999 00:00
Date: Tue, 21 Sep 1999 00:00
57 lines
2211 bytes
2211 bytes
xxx:
Choose a data type that will contain the values you are working with
(like long) Your paticular addition is 1 over the size of positive
values that you can cram into an int (2147483647).
A good exercise for a student is to look at the input and determine if
it is valid (or in this case watch the running total); that's probably
being saved for a future assignment.
-Rich
xxx wrote:
>
> // Sum.java til �velse 2
>
> import java.io.*;
>
> public class Sum
> {
> static BufferedReader keyboard = new
> BufferedReader(new InputStreamReader(System.in));
> static PrintWriter screen = new PrintWriter(System.out, true);
>
> public static void main(String[] args) throws IOException
> {
> int a, b, sum; // erkl�ring af variable
>
> screen.println("Indtast 1.tal");
> a = new Integer(keyboard.readLine()).intValue();
>
> screen.println("Indtast 2.tal");
> b = new Integer(keyboard.readLine()).intValue();
>
> sum = a + b;
> screen.println("Summen er\t" + sum);
>
> screen.println("\nTAST ENTER\n");
> keyboard.readLine();
>
> }
> }
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Rich Wilkman
Quality Assurance Manager
Borland JBuilder Team
If you see something that looks like an opinion up there,
it's mine and mine alone.
Mail sent to me from the newsgroups won't bounce but will
be ignored. If I have time, I'll respond, but you have
a better chance if you confine your posts to the newsgroups
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Technical Details
Message-ID:
<37E7A59E.2AABE2A4@inprise.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7s7jtb$nrs3@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 111d45,38056fd1a63a0ae6 X-Google-Attributes: gid111d45,public From: Rich Wilkman <rwilkman@inprise.com> Subject: Re: Problems when adding the two numbers 2147483646 and 2 in Jbuilder......WHY...WHY....WHY Date: 1999/09/21 Message-ID: <37E7A59E.2AABE2A4@inprise.com> X-Deja-AN: 527857232 Content-Transfer-Encoding: 8bit References: <7s7jtb$nrs3@forums.borland.com> X-Accept-Language: en Content-Type: text/plain; charset=iso-8859-1 Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing