0
Battleship code fix
So I have a Battleship game code, problem is i have written, that ships are placed randomly, but task is to allow user input ship locations. Can anyone help to fix it? https://code.sololearn.com/chAmCj39Oga2/#java
3 Réponses
+ 1
According to your problem description : you can use taking user input instead of random number generation. If the input number is not within the range as expected, continue asking user input again or raise error.
coordinates[i] = new Random().nextInt(gameLength);
I only found this where you are using random() so instead this write
do
{
coordinates[i] = new Scanner(System.in).nextInt();
}while(coordinates[i] >gameLength);
0
Thanks, it fixed that i can enter them, but it doesnt stop,and doesnt returnt to gameboard #Jayakrishna
0
You have tricky code that can't be tested here. Accoding to your code, it will return to calling statement. But also you can create only one object of Scanner so create object of scanner as static or class level object.. It works then I think.