-2

I'm trying to learn java. When i'm running the code in DrJava i get this message: cannot find symbol. I tried several things but nothing works. When i'm searching the internet I get most of the times the problem is 'import java.util.Random;', but I wrote that down. Anyone knows what the problem is? Thanks a lot!

import java.util.Random;

public class dobbelsteen {
    public static void main(String[]args) {
        int dobb1;
        int dobb2;
        int dobb3;
        int dobb4;
        int dobb5;

        boolean alldobb = true;

        do {
            dobb1 = random.nextInt(6) + 1;
            dobb2 = random.nextInt(6) + 1;
            dobb3 = random.nextInt(6) + 1;
            dobb4 = random.nextInt(6) + 1;
            dobb5 = random.nextInt(6) + 1;
            if (dobb1 != dobb2 && dobb2 != dobb3 && dobb3 != dobb4 && dobb4 != dobb5) { 
                System.out.println(dobb1 + dobb2 + dobb3 + dobb4 + dobb5); 
           }
            else {
                System.out.println(dobb1 + dobb2 + dobb3 + dobb4 + dobb5);
                alldobb = false;
            }
        }while(alldobb);
    }
}
Valentin Michalak
  • 2,089
  • 1
  • 14
  • 27
Frank
  • 3
  • 2

2 Answers2

1

You need to create a instance of the class random so that you can use the object and it´s method.

Random random = new Random();
random.nextRandom(X,Y);

You just can call Class.method() when the method is declared as static - so there is no need to initalize it.

LenglBoy
  • 1,451
  • 1
  • 10
  • 24
1

random is not declared, you need to do it:

Random random = new Random();
HBo
  • 635
  • 6
  • 16