Author |
Message |
kensie
Joined: 30 Jul 2008 Posts: 1
|
|
Random Problem Challenge |
|
What should the format of the answer be? Just a number? also many numbers would throw an Exception which one will work?
|
|
Fri Feb 27, 2009 11:02 pm |
|
 |
gfoot
Joined: 05 Sep 2007 Posts: 269 Location: Brighton, UK |
|
|
|
Just a number. I'm not a Java expert so I can't comment on how many numbers would throw an exception... but if the site is not accepting your answers, have you tried compiling the code and trying them out to make sure they really do throw exceptions?
|
|
Sat Feb 28, 2009 1:59 am |
|
 |
sabretooth

Joined: 12 Jul 2009 Posts: 61
|
|
|
|
I really don't understand this problem.
2147483647 is the max integer value in java - therefore this value and every possible value above this will cause an Exception. So why isnt it accepted? If you are looking for a 'specific' integer then the challenge should say so.
Any advice?
sabre
|
|
Tue Jul 21, 2009 8:31 pm |
|
 |
gfoot
Joined: 05 Sep 2007 Posts: 269 Location: Brighton, UK |
|
|
|
It's asking specifically for a value for 'randomNumber', which is declared as an int, so your answer has to be a valid int. I don't think 2147483647 will cause an exception, so no, that's not the answer, and higher numbers are not valid ints, so they don't count as answers either.
|
|
Tue Jul 21, 2009 10:16 pm |
|
 |
Theino
Joined: 15 Mar 2009 Posts: 8
|
|
|
|
The answer is a valid int.
There is only one answer and thus only one valid int that would cause an exception.
|
|
Wed Jul 22, 2009 12:28 am |
|
 |
sabretooth

Joined: 12 Jul 2009 Posts: 61
|
|
|
|
Many thanks for the response
sabre
edit - solved.
Thanks again 
|
|
Wed Jul 22, 2009 8:36 am |
|
 |
General_Payne
Joined: 20 Jun 2011 Posts: 20
|
|
Struggling |
|
Guessing there is some trick to this? Fairly sure i have run it for everything in the range -2147483647 to 2147483647 without an error
[Edit] -Scratch That. Was Being Retarded. Can't believe i spent over an hour on something so easy and obvious!!
|
|
Wed Dec 07, 2011 7:16 pm |
|
 |
meis
Joined: 28 Aug 2012 Posts: 16 Location: Italy |
|
|
|
I've rewritten it in PHp to read it better (I'm more familiar with it).
So I have:
 |
 |
<?php
function bucketFromRandom($randomNumber) {
$a = array();
for ($i = 0; $i < 10; $i++)
$a[$i] = $i * $randomNumber;
$index = abs($randomNumber) % 10;
return $a[$index];
}
echo bucketFromRandom(2147483648);
?> |
Will it work in PHP too?
And what do I have to look for? I can't get it! But maybe i just don't understand what an exception is...
|
|
Sat Jun 01, 2013 3:16 pm |
|
 |
Rat62

Joined: 23 Nov 2010 Posts: 17
|
|
|
|
 |
 |
I've rewritten it in PHp to read it better (I'm more familiar with it).
So I have:
 |
 |
<?php
...
?> |
Will it work in PHP too?
... |
Many challlenges on this site urge you to learn new things: Computer languages, cryptologic techniques, file formats.
This one is special to Java (and probably close relatives like C#). It won't work in PHP.
|
|
Wed Jun 05, 2013 2:30 pm |
|
 |
|