Hei,
Вам нужно сохранить вывод в основном или просто распечатать его, если вам не нужно его использовать.
public static void main(String[] args) {
convert13to7(7);
}
Заменить на
public static void main(String[] args) {
//if you want just to check the output
System.out.println(convert13to7(7));
//or if you want to use it further
int holdValue = convert13to7(7);
}
Вы также должны обрабатывать исключения (по крайней мере, ArrayIndexOutOfBoundsException).Вот пример использования лямбды (почти то же самое)
interface lambda{
int getGrades(int[] scale13, int[] scale7, int grade);
}
public class Grades{
public static void main(String[] args) {
lambda output = (int[] scale13, int[] scale7, int grade) ->{
int newGrade = 0;
try {
for (int i = 0; i < scale13.length; i++)
if (grade == scale13[i])
newGrade = scale7[i];
}catch(ArrayIndexOutOfBoundsException e) {
System.out.println("ArrayIndexOutOfBoundsException Exeption.");
}
return newGrade;
};
int[] scale13 = {00, 03, 5, 6, 7, 8, 9, 10, 11, 13};
int[] scale7 = {-3, 00, 00, 02, 4, 7, 7, 10, 12, 12};
System.out.println(output.getGrades(scale13, scale7, 7));
}
}