Hi there, as one of my first programs in java, I thought I will do a simple (!) lottery program...needless to say it doesn't compile, and after looking at it for quite awhile trying to unsuccessfully spot the error (I am not sure how to debug in netbeans, any advice on that very welcome too of course) I thought that it is time for some help. here's the program (compiled with netbeans):
package lottery;
import static java.lang.System.out;
import java.util.Scanner;
import java.util.Random;
public class Lottery {
public static void main(String[] args) {
int[] numbers = new int[49];
//int[] numbers = new int[49];
int[] winningNumbers = new int[6]; //array holding 6 random numbers
int[] userNumber = new int[6]; //array holding the input
Scanner theNumbers = new Scanner(System.in);
int guesses;
int counter;
int i;
/*
for(i = 0; i < numbers.length; i++){
numbers[i] = i + 1;
out.println(numbers[i]);
}
*/
//generate 6 random numbers
for(i = 0; i < winningNumbers.length; i++ ){
int randomNums = new Random().next(49) + 1;
winningNumbers[i] = randomNums;
}
out.println("Enter the 6 numbers");
for(i = 0; i < userNumber.length; i++){
guesses = theNumbers.nextInt();
userNumber[i] = guesses;
out.println(userNumber[i]);
if(winningNumbers[i] == userNumber[i] ){
counter+=1;
}
}
if (counter == 6){
out.println("you won!! COngratulations!");
else
out.println("you lose!");
}
}
}
SO the idea behind this is that the computer generates 6 random number in the range of 1 to 49, and store them in an array, the user inputs his own 6 guesses, stores them into an array, then each entry is compared to what the computer has stored and for each right guess the counter is incremented by 1. If the counter is 6 then you win, if not you lose.
Now, netbeans is giving me some strange errors and warnings:
1) with this import java.util.Scanner;
it says thatthis doesn't correspond to the specified code style...?!
2)here int randomNums = new Random().next(49) + 1;
it tells me that next(Int) has protected access, whatever that means;
3) at the else
level it says: 'else' without 'if'...ehm?!
4) at counter+=1;
it says variable counter might not have been initialised
5) the last }
says "class, inteface or enum expected"
Any idea what I have done wrong? Please take in consideration that as I said I am very new to Java
thanks