【发布时间】:2015-02-05 00:16:11
【问题描述】:
所以每次我尝试编译我的 .java 文件时都会出现以下错误
“错误:变量 max 已在方法 main(String[]) 中定义 整数最大值 = j; "
而且我无法弄清楚问题是什么或如何解决它。现在已经卡了大约2个小时了。我最终要做的是在我的数组中输入一个整数,然后将该整数中的数字从最小到最大排序以提供上下文。
这是我的代码中的相关部分:
int[] wholeNumber = new int[1];
//Sorting algorithm beginning
int n = wholeNumber.length;
System.out.println("Length of array is :" + n); //Array length displayed
for(int i = 0; i < 1; i++)
{
System.out.println("Hello!");
int max = i;
for(int j = i+1; j < 1; j++)
{
if (wholeNumber[j] > wholeNumber[max])
{
int max = j;
}
}
if (max != i)
{
wholeNumber[i] = wholeNumber[max];
wholeNumber[max] = wholeNumber[i];
}
}
//Sorting algorithm end
【问题讨论】:
标签: java sorting if-statement for-loop compiler-errors