This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Java Rules Roundup #47

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(#47) What happens when you divide an integer by a variable with a value of 0?

o Compiler Error
o Compiles and Runs
o Runtime Exception

Doesn't the answer depend on information that is not presented in the question, namely the type of the second variable?

Thanks,
jdmaddison
 
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think there is a little bit of an assumption here that because the variable has the value 0 it is either int, byte, short, or char. Any of these will throw a runtime error.

Where I think this question gets a little off is that you can do the following.

double a = 0;
5/a;

and you don't get a compile or runtime error.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If u did't assume that the Data type of the second variable integer then only it will give the runtime Airthmetic Exception

Otherwise if one of the value is float/double then it will Run succesfully

Mukesh
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!