我在 python 中测试了我的算法,它完全符合我的要求。现在我只想用 java 编写相同的代码。我遇到了两个问题。一个在第 7 行,一个在第 8 行。我想知道为什么即使我在 for 循环中有 int i 也没有检测到 i。我下学期要学习 Java,如果这是一个非常容易处理的错误,我深表歉意。
public class HelloWorld{
public static void main(String []args){
int[] a = {1, 0, 12, 11};
int max = a[0];
for (int i:a); {
if (max < i); {
max = i;
}
}
System.out.print("max"); // if method is void, then cannot return value
}
}
最佳答案
从终止这些语句的 for
和 if
语句中删除尾随分号
关于java在for循环中改变值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27608890/