Я пишу код, который вычисляет максимальное число в моей переменной args, а также наибольшую разницу между самым высоким и самым низким целым числом в args.
В настоящее время мой код выглядит так:
public int max(int [] args) {//array of ints
int m = args[0]; // first element
//initialisation; condition; update
for (int j = 1; j < args.length; ++j) {
// statement in a block:
if (m < args[j]) {
m = nums[j];
// if m is less than the j-th element
// then store this new smaller value
}
}
return m;
}
public int min(int [] args) {//array of integerss
int mi = nums[0]; // first element
//initialisation; condition; update
for (int j = 1; j < args.length; ++j) {
// statement in a block:
if (mi > args[j]) {
mi = args[j];
// if m is greater than the j-th element
// then store this new largest value
}
}
return mi;
}
// вычисляем среднее значение путем деления суммы чисел на количество
public void main(String [] args) {
System.out.println(args[0]);
SimpleCalc fm = new SimpleCalc();
**System.out.println(fm.max(nums));**
**System.out.println(fm.max(nums) - fm.min(nums));**
Он возвращал значения, когда я использовал массивы, но, похоже, он не компилируется с аргументами. Я не уверен, как это исправить.