• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

need to omit "2147483647*2147483647=1"

 
Ranch Hand
Posts: 50
1
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so i have written code that takes three inputs (A, B and C)
if when multiplied any of the arguments equal the other it prints the corresponding sum;
i have used simple if statements

simple right? or not, after testing i found the args 1 21472147483647483647 2147483647
would output all three as correct. how do i prevent this from happening, i understand due to "overflow" this is infact correct (in binary terms) but i would like it to not print

but only

Thanks in advance guys
 
Stan Austin
Ranch Hand
Posts: 50
1
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry managed to post in wrong forum if a mod want to move to beginning in java, i would be grateful!
Thanks
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what types are a and b?  (that's a hint as to what the problem is...)
 
Stan Austin
Ranch Hand
Posts: 50
1
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All three of them are ints the breif states use only ints
 
Stan Austin
Ranch Hand
Posts: 50
1
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stan Austin wrote:All three of them are ints the breif states use only ints


correction it state all three inputs must be ints... changing them in to longs though means it will not throw the exception so raises another issue right?
 
author
Posts: 23956
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stan Austin wrote:
correction it state all three inputs must be ints... changing them in to longs though means it will not throw the exception so raises another issue right?



What exception won't be thrown?

Henry
 
Marshal
Posts: 79514
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stan Austin wrote:. . .  it will not throw the exception so raises another issue right?

What exception? There is no exception thrown if you suffer an arithmetic overflow.
 
Stan Austin
Ranch Hand
Posts: 50
1
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:

Stan Austin wrote:
correction it state all three inputs must be ints... changing them in to longs though means it will not throw the exception so raises another issue right?



What exception won't be thrown?

Henry



The input must be Ints as such it would throw an exception if the argument entered was a long not an int.
however i realised that i could ask the user for the int, then long a2 = int a to convert the in to a long after the fact.
hence now resolved.
Thanks though guys!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic