Results 1 to 20 of 40
- 11-17-2009, 01:10 PM #1
Member
- Join Date
- Nov 2009
- Posts
- 75
- Rep Power
- 0
changing my program to array working program
hi guys i have my program up and running no problems but i need to change it to an array program. im new to java and finding this part quite difficult any input would be appreciated alotJava Code:import java.util.Random; public class Random100 { /*This is a program to generate random numbers between 1 and 999 with no repetitions in the sequence */ public static void main(String[] args) { Random rand = new Random(); for (int count = 0; count < 10; count++) //allocates the rows of 10 x 10 random numbers { System.out.println(); for (int i = 0; i < 10; i++) { int gennum = rand.nextInt(999); //This is the maximum that the program generates the numbers to int finalnum = String.valueOf(gennum).length(); if (finalnum == 1) //if the final number has one number so say 9 the program will add two zero's { System.out.print("00" + (gennum) + " "); } if (finalnum == 2) //if the final number has two numbers so say 19 the program will add one zero { System.out.print("0" + (gennum) + " "); } if (finalnum == 3) //and if program has three numbers the program will just output the generated number { System.out.print((gennum) + " "); } } } } }
- 11-17-2009, 01:19 PM #2
I find it quite difficult too, as I have no idea what an array program is.
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 11-17-2009, 01:19 PM #3
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
What do you want the array to be doing?
Have you read an arrays tutorial yet?
- 11-17-2009, 02:36 PM #4
Member
- Join Date
- Nov 2009
- Posts
- 75
- Rep Power
- 0
basically i want an array of 100 random numbers. I have yes but would like a lil guidence as to how i could alter my program to make it an a program with 100 random numbers using arrays
- 11-17-2009, 02:36 PM #5
Member
- Join Date
- Nov 2009
- Posts
- 75
- Rep Power
- 0
any input would be really really helpful. thank you
- 11-17-2009, 02:44 PM #6
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
First you declare and initialize the array.
Then you assign values into it in the loop that is generating the numbers.
- 11-17-2009, 02:49 PM #7
Member
- Join Date
- Nov 2009
- Posts
- 75
- Rep Power
- 0
hey r035198x many thanks for your speedy reply, i did try that originally but i encountered a few error messages in this process. do u want to know the error messages that i am encountering?
- 11-17-2009, 02:51 PM #8
Also post the code, the error messages are not helpful alone.
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 11-17-2009, 02:58 PM #9
Member
- Join Date
- Nov 2009
- Posts
- 75
- Rep Power
- 0
hey phHein here is my code with attempted ammendments to it, to modify my code into an array.still getting errors. plz help lol
Java Code:import java.util.Random; public class Random100 { /*This is a program to generate random numbers between 1 and 999 with no repetitions in the sequence */ public static void main(String[] args) { int[] rand = new int[100]; // one-dimensional array of possible sums initializeArray(rand); randomizeArray(rand); for (int count = 0; count < 10; count++) //allocates the rows of 10 x 10 random numbers { System.out.println(); for (int i = 0; i < rand.length; i++) { int gennum = rand.nextInt(999); //This is the maximum that the program generates the numbers to int finalnum = String.valueOf(gennum).length(); if (finalnum == 1) //if the final number has one number so say 9 the program will add two zero's { System.out.print("00" + (gennum) + " "); } if (finalnum == 2) //if the final number has two numbers so say 19 the program will add one zero { System.out.print("0" + (gennum) + " "); } if (finalnum == 3) //and if program has three numbers the program will just output the generated number { System.out.print((gennum) + " "); } } } } }
- 11-17-2009, 03:02 PM #10
Where are the error messages?
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 11-17-2009, 03:08 PM #11
Member
- Join Date
- Nov 2009
- Posts
- 75
- Rep Power
- 0
im using the cmd how can i print off the errors?
- 11-17-2009, 03:13 PM #12
Mark the output with the mouse, press enter and paste them here.
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 11-17-2009, 03:18 PM #13
Member
- Join Date
- Nov 2009
- Posts
- 75
- Rep Power
- 0
M:\javalab\lab6>
M:\javalab\lab6>javac Random100.java
Random100.java:19: cannot find symbol
symbol : method initializeArray(int[])
location: class Random100
initializeArray(rand);
^
Random100.java:20: cannot find symbol
symbol : method randomizeArray(int[])
location: class Random100
randomizeArray(rand);
^
Random100.java:29: cannot find symbol
symbol : method nextInt(int)
location: class int[]
int gennum = rand.nextInt(999); //This is the maximum th
at the program generates the numbers to
^
3 errors
thanks alot =)Last edited by Chewart; 11-17-2009 at 03:19 PM. Reason: copyied all my cmd lol
- 11-17-2009, 03:30 PM #14
That method doesn't exist!
Originally Posted by Chewart
That method doesn't exist either!
Originally Posted by Chewart
rand is now an int[], that does not have a method called nextInt.
Originally Posted by Chewart Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 11-17-2009, 03:38 PM #15
Member
- Join Date
- Nov 2009
- Posts
- 75
- Rep Power
- 0
honestly im really baffled on this program phHein. possibly could you have some input into my program as im not entirely understanding it fully :S
- 11-17-2009, 03:59 PM #16
Are you telling me that you don't understand your own program?!
What exactly is your problem?Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 11-17-2009, 04:02 PM #17
Member
- Join Date
- Nov 2009
- Posts
- 75
- Rep Power
- 0
thanks for the reply phHein. i do understand my program its just when im trying to implement the arrays in my program im not understanding fully. arrays is a part on the java language that ive only just been introduced to so, any lil bit of info that could possibly help me on my way to java program success in the future would be great =)
- 11-17-2009, 04:03 PM #18
Oh, ok. This tutorial is quite good: Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 11-17-2009, 04:09 PM #19
Member
- Join Date
- Nov 2009
- Posts
- 75
- Rep Power
- 0
many thanks for the replies to my posts phHein. without telling me the right code, would i have to ammend my random number program that i have submitted alot in order to get my program working whilst using arrays??
- 11-17-2009, 04:15 PM #20
You're welcome. No, you dont need to change a lot. Go back to the code in your first reply and add an int[]. That should not break anything. Next you fill the array with those 100 randomly generated ints. If that doesn't break anything, use a new loop to print the contents of the array.
That should get you started. If you get stuck, ask again.Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
Similar Threads
-
Driving me insane - Program not working as it should ><
By mainy in forum New To JavaReplies: 1Last Post: 08-27-2009, 01:20 PM -
Working on a menu program...using exceptions
By Nightwarrior in forum New To JavaReplies: 0Last Post: 04-16-2009, 04:40 AM -
Program working fine on netbeans but not when run with jar file
By nvlachos in forum Advanced JavaReplies: 2Last Post: 03-16-2009, 07:52 PM -
[SOLVED] Changing the look of butons in program
By linux1man in forum AWT / SwingReplies: 8Last Post: 03-14-2009, 06:04 PM -
My program is not working
By MICHAELABICK in forum New To JavaReplies: 6Last Post: 12-22-2008, 11:05 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks