Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thinking in Java excercise

 
Sami Devine
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exercise 9: (1) Display the largest and smallest numbers for both float and double exponential notation.

This is my solution to this excercise. Is this the expected answer? I manipulated the bases and exponent till I did not get Floating point too large error.

 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint: look at the classes Double and Float.
 
Sami Devine
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry. I think I got it right now.



 
Rob Spoor
Sheriff
Pie
Posts: 20605
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure those are the right constants? Double.MAX_EXPONENT is 1023, I don't think that's the maximum value (hint hint) for a double.
 
Sami Devine
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob thanks for the hint
This question was under the Exponents section. So I think the expected answer is exponents and not MAX_VALUE and MIN_VALUE.

 
Rob Spoor
Sheriff
Pie
Posts: 20605
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the question is too vague about this. Do they mean the largest double value which can be written in exponential notation, or do they mean the largest exponential part when writing a double in exponential notation?
I would post both answers and tell them to pick which one they want
 
fred rosenberger
lowercase baba
Bartender
Posts: 12180
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouldn't the smallest number also be negative? -100 is smaller than .0000000000000000000000000001
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic