-
Notifications
You must be signed in to change notification settings - Fork 226
Task9 #826
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Task9 #826
Conversation
| return ""; | ||
| } | ||
| int[][] matrixLengthCount = new int[n + 1][2]; | ||
| int[][] matrix = new int[n][n]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Использование массивов в этой задаче - чит. Предлагаю попробовать без них:)
| if (k == 1) { | ||
| spaceCount++; | ||
| } else { | ||
| int temp = ((matrixLengthCount[k][0] - matrixLengthCount[k - 1][0]) - (matrixLengthCount[k - 1][0] - matrixLengthCount[k - 2][0])) / 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Строка кода должна быть ограничена 120 символами. Считается, что именно столько влазит в один экран при стандартных настройках. В IDE обычно даже вертикальная линия есть, отмечающая это значение в рабочей зоне
| builder.insert(matrixLengthCount[i - 1][0], ' '); | ||
| } | ||
| } | ||
| return builder.toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return getNum(rows - 1, cols - 1) + getNum(rows - 1, cols); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Файл должен завершаться пустой строкой https://stackoverflow.com/questions/729692/why-should-text-files-end-with-a-newline
| maxLength = temp.length() - 1; | ||
|
|
||
| for (int i = 0; i < rows; i++) { | ||
| temp.delete(0, temp.length()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Удаление всей строки?) зачем? Не проще новую строку создать? Да и в целом логичнее в новую переменную вынести
| temp.append(getNum(i, j)).append(" "); | ||
| } | ||
| temp.deleteCharAt(temp.length() - 1); | ||
| result.append(" ".repeat(Math.max(0, (maxLength - temp.length()) / 2))).append(temp).append('\n'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Math.max(0, (maxLength - temp.length()) / 2) - в переменную с понятным названием.
Кроме того, епочки вызовов лучше оформлять по правилу точка-строчка - каждый новый верхнеуровневый вызов с новой строки. Читается лучше, в более старых версиях джавы (кажется, до 17) облегчит локализацию NullPointerException:
int shift = Math.max(0, (maxLength - temp.length()) / 2); //здесь у тебя еще скобки лишние в вычитании
result.append(" ".repeat(shift))
.append(temp)
.append('\n');| return getNum(rows - 1, cols - 1) + getNum(rows - 1, cols); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В целом, стало намного лучше


No description provided.