What are the chances that the number will be guessed in this code:
Code:
package numberguesser;
import java.util.Random;
public class Main {
public static void main(String[] args) {
int guess, number;
Random rand = new Random();
number = rand.nextInt(1000000000) + 1;
guess = rand.nextInt(1000000000) + 1;
while (guess != number) {
System.out.println("Trying " + guess);
guess = rand.nextInt(1000000000) + 1;
}
System.out.println("The number was guessed. It was " + number);
}
}
Comment