Register and join over 40,000 other developers!
Recent Topics
-
The Game You Are Waiting For?
WendellHarper - Dec 06 2020 01:21 PM
-
Quora and Reddit Backlinks
WendellHarper - Dec 06 2020 01:14 PM
-
Delete account
pindo - Jul 23 2020 01:33 AM
-
Print specific values from dictionary with a specific key name
Siten0308 - Jun 20 2019 01:43 PM
-
Learn algorithms and programming concepts
johnnylo - Apr 23 2019 07:49 AM
Recent Blog Entries
Recent Status Updates
Popular Tags
- networking
- Managed C++
- stream
- console
- database
- authentication
- Visual Basic 4 / 5 / 6
- session
- Connection
- asp.net
- import
- syntax
- hardware
- html5
- array
- mysql
- java
- php
- c++
- string
- C#
- html
- loop
- timer
- jquery
- ajax
- javascript
- programming
- android
- css
- assembly
- c
- form
- vb.net
- xml
- linked list
- login
- encryption
- pseudocode
- calculator
- sql
- python
- setup
- help
- game
- combobox
- binary
- hello world
- grid
- innerHTML

Java Programming Question
Started by oldezwe, Feb 25 2011 08:10 PM
2 replies to this topic
#1
Posted 25 February 2011 - 08:10 PM
-List of names in a database
-names have double assigned to them, x
-each name has random 10 digit double generated from 0 to x
-the name with the highest number double is assigned to a variable
-if two names generate the same double then the name with in the list is assigned to the variable
-once a name is assigned to the variable, it falls out of queue and cannot be assigned again for another 24 hours
What components of Java do I need to be able to understand to know how to do this?
Or if you have pre-written code with similar functionality that would be helpful too.
Thanks tons and much love
-names have double assigned to them, x
-each name has random 10 digit double generated from 0 to x
-the name with the highest number double is assigned to a variable
-if two names generate the same double then the name with in the list is assigned to the variable
-once a name is assigned to the variable, it falls out of queue and cannot be assigned again for another 24 hours
What components of Java do I need to be able to understand to know how to do this?
Or if you have pre-written code with similar functionality that would be helpful too.
Thanks tons and much love
#2
Posted 25 February 2011 - 09:54 PM
import java.util.Random; import java.util.Iterator; import java.util.List; import java.util.ArrayList; public final class RandomGaussian { public static final void main(String... aArgs){ Random randomGenerator = new Random(); List<Integer> level = new ArrayList<Integer>(); level.add(37); level.add(2); level.add(2); level.add(4); int position = 0; int listsize = level.size(); while(position <= listsize){ int levelDouble = randomGenerator.nextInt(level.get(position)); log("Generated : " + levelDouble); position = position + 1; } log("Done."); } private static void log(String aMessage){ System.out.println(aMessage); } }
Why does this give me an array out of bounds error?
#3
Posted 25 February 2011 - 11:51 PM
Try changing this:
But anyways, your getting an error because an array's value's start at 0. When you call the ".Size" function, it returns the size of the array. So for example you would have an array like this:(pseudo)
Hope you understand, Im pretty tired lol ~ Committed.
int listsize = level.size();to this:
int listsize = level.size()-1;That should work, but Im not sure cause I dont have a Java IDE.
But anyways, your getting an error because an array's value's start at 0. When you call the ".Size" function, it returns the size of the array. So for example you would have an array like this:(pseudo)
ArrayName[0] ArrayName[1] ArrayName[2] ArrayName[3]Now when you call the ".Size" function it returns 4 because there's four values in the array. But really the answer is 3 because we start holding value's at 0 not 1.
Hope you understand, Im pretty tired lol ~ Committed.
There IS a war going on for your mind.
Nothing of eternal significance happens besides prayer.
Nothing of eternal significance happens besides prayer.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download