Update 代码可读性.md

更新示例代码,使其可以编译运行。
This commit is contained in:
CyC2018
2026-10-26 22:04:02 +08:00
parent 8aa1b59ec7
commit c942f9509a
+7 -7
View File
@@ -272,17 +272,17 @@ var setFirstEmptyInput = function(new_value) {
```java
int findClostElement(int[] arr) {
int clostIdx;
int clostDist = Interger.MAX_VALUE;
int clostIdx = -1;
int clostDist = Integer.MAX_VALUE;
for (int i = 0; i < arr.length; i++) {
int x = ...;
int y = ...;
int z = ...;
int value = x * y * z;
int dist = Math.sqrt(Math.pow(value, 2), Math.pow(arr[i], 2));
int dist = (int) Math.sqrt(Math.pow(value, 2) + Math.pow(arr[i], 2));
if (dist < clostDist) {
clostIdx = i;
clostDist = value;
clostDist = dist;
}
}
return clostIdx;
@@ -293,13 +293,13 @@ int findClostElement(int[] arr) {
```java
public int findClostElement(int[] arr) {
int clostIdx;
int clostDist = Interger.MAX_VALUE;
int clostIdx = -1;
int clostDist = Integer.MAX_VALUE;
for (int i = 0; i < arr.length; i++) {
int dist = computDist(arr, i);
if (dist < clostDist) {
clostIdx = i;
clostDist = value;
clostDist = dist;
}
}
return clostIdx;