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

11th Nov 2020, 11:22 AM
Eric Kazhus
Eric Kazhus - avatar
3 Respuestas
+ 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);
11th Nov 2020, 1:19 PM
Jayakrishna 🇮🇳
0
Thanks, it fixed that i can enter them, but it doesnt stop,and doesnt returnt to gameboard #Jayakrishna
11th Nov 2020, 2:35 PM
Eric Kazhus
Eric Kazhus - avatar
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.
11th Nov 2020, 4:13 PM
Jayakrishna 🇮🇳