Random numbers
843785Sep 17 2008 — edited Sep 17 2008Hi All,
I just started my Java course and I have NO previous programming knowledge.
I have plenty of assignments/exercises to do and I am struggling right from the start.
The book they gave me as a study guide is "SAMS TEACH YOURSELF JAVA 2 IN 21 DAYS",
but it doesn't tell ME much.
The first question I have to do is and want to ask is:
** Load three random numbers between 0 and 100 into an array.
Create another string array with the values "good, "bad", and "average".
If the third random number is less than 70, continue randomizing until the value is greater than 70.
Print the values with their index values and the appropriate String array message:
Number smaller than 40 - bad
Number greater than or equal to 40 and smaller than 80 - average
Number greater than or equal to 80 - good
**
I have tried to do this on my own but can't seem to get it right (below is my code)
{code}
package org.other.exercises;
public class Random1 {
public static void main(String[] args) {
int[] values = new int[3];
for (int i = 0; i < values.length; i++) {
values[i] = (int)(Math.random()*100);
}
String[] message = {"good", "average", "bad"};
if (values[2] < 70) {
values[2] = (int)(Math.random()*100);
}
if (values <= 40 ) {
System.out.println(values + " " + message[2]);
}
if (values < 80) {
System.out.println(values + " " + message[1]);
}
if (values > 80) {
System.out.println(values + " " + message[0]);
}
}
}
{code}
If someone could PLEASE help me and tell me what or where I'm going wrong I would very much appreciate it.
Thank you
Smirre