• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception in thread "main" java.lang.ArithmeticException: / by zero  RSS feed

 
Greenhorn
Posts: 4
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this code here that is bugging.
I want to create a simple market that calculates your money depending on how much the price of gold is.
If I have this code the price is always 0, and it crashes once I try to calculate the money I have left, because it tries divide 0, (I think).


However, when I try this code, it says the following error code: 'Exception in thread "main" java.lang.ArithmeticException: / by zeroat Tutorial.main(Tutorial.java:24)'


I have no idea what the cause is. Help would be really appreciated.
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Exceptions have stack traces. This should help give a first location on where it is happening.

Henry
 
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint: what are the possible values for randomNum? And of randomNum/100? (Remember: randomNum is an int)
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing to do with the exception but please explain what lines No 19 and 31 do.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!