I have a problem with my code, it's a simple dice game:
import java.util.Random;
class Zaruri {
public static void main(String args[]) {
Random roll = new Random();
int[] zar = new int[2];
for (int i = 0; i < 1; i++) {
for(int k = 0; k < 2; k++){
zar[i] = (int) (roll* 6) + 1;
}
if (zar[0] == zar[1]) {
System.out.println("Your numbers are : " + zar[0] + " and " + zar[1] + "\nYou won! \nYEEEY!!");
} else {
System.out.println("Your numbers are : " + zar[0] + " and " + zar[1] + "\nYou lost, better luck next time!");
}
}
}
}
I don't know how to make it work,first it won't let print out the second dice(it comes allways 0) and if i put more then 1 roll and (roll.nextDouble * 6) + 1; it will work,but i don't want more then 1 roll. CAn you help me ? What am i doing wrong??