I study java. I decided to make the sea battle a "difficult" way to learn some things. The game will ask the cage, which should shoot a gun. It is necessary to translate the input string into int, since all cells are numbered into int.
Closed due to the fact that the essence of the issue is incomprehensible by the participants Enikeyschik , AK ♦ , freim , entithat , Kromster 15 May at 11:59 .
Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .
|
1 answer
I understand that for the standard field 10x10, there will be continuous numbering, i.e., A1 has the number 01, A2 - 02 ... B1 - 11 ... J10 - 100. Then, after validation, we divide the coordinate into a letter (char) and digit (int).
String coord = "C7"; // например, получили C7 char ch = coord.charAt(0); // Тут можно проверить получился ли символ из допустимого диапазона int number = Integer.parseInt(coord.charAt(1)); int absoluteCoord = 10 * (ch - 'A') + number; Something like this
- one1) 10 is no longer digit, but number :)
int number = Integer.parseInt(coord.charAt(1))2) it seems to me that there must be a multiplication by 10 somewhere:((ch - 'A') * 10) + number? or so((ch - 'A') * 10) + (number - 1)for numbering from scratch? - Sergey - @Sergey yes, I guess. He wrote in the phone, he just put a general idea. Not multiply by 10, but horizontally by the size of the field (if the field is non-standard) - Oleksiy Morenets
|