Итак, я опубликовал вчера вечером некоторые проблемы, но мой код был беспорядок, поэтому я переписал его. Прежде всего, что нужно сделать, это напечатать сетку чисел 3х3, затем найти все о седла и напечатать их. (седла - это номера, которые являются самыми низкими в столбце, но самые высокие в строке).Неизвестная ошибка в Java?
Когда бежал, это консольный вывод:
7 1 18
15 10 3
0 15 2
Седла являются:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The operator < is undefined for the argument type(s) int[], int[]
The operator < is undefined for the argument type(s) int[], int[]
Type mismatch: cannot convert from int[] to int
The operator < is undefined for the argument type(s) int[], int[]
The operator < is undefined for the argument type(s) int[], int[]
Type mismatch: cannot convert from int[] to int
The operator < is undefined for the argument type(s) int[], int[]
The operator < is undefined for the argument type(s) int[], int[]
Type mismatch: cannot convert from int[] to int
at Main.findLowest(Main.java:66)
at Main.findSaddles(Main.java:54)
at Main.main(Main.java:16)
Вот мой код, немного грязный, но не было времени, чтобы очистить его еще:
import java.util.ArrayList;
import java.util.Random;
public class Main {
static int[][] Grid = new int[3][3];
static ArrayList<Integer> Saddles = new ArrayList<Integer>();
static Random random = new Random();
static int currentColumn; //will be use by various methods to fill/read from array
public static void main(String[] args) {
fillArray();
printArray();
findSaddles();
}//end of main()
//fill the array with random "ints"
public static void fillArray(){
currentColumn = 0;
int indexsFilled = 0;
while(indexsFilled != 9){
Grid[0][currentColumn] = random.nextInt(21);
Grid[1][currentColumn] = random.nextInt(21);
Grid[2][currentColumn] = random.nextInt(21);
indexsFilled += 3;
currentColumn += 1;
}//end of while loop
}//end fillArray()
//print array's contents
public static void printArray(){
currentColumn = 0;
int indexsPrinted = 0;
while(indexsPrinted != 9){
System.out.print(Grid[0][currentColumn] + " ");
System.out.print(Grid[1][currentColumn] + " ");
System.out.print(Grid[2][currentColumn] + "\n");
indexsPrinted += 3;
currentColumn += 1;
}//end of while loop
}//end of printArray()
public static void findSaddles(){
System.out.println("The saddles are: ");
currentColumn = 0;
findLowest(currentColumn);
findLowest(currentColumn + 1);
findLowest(currentColumn + 2);
for(int i = 0; i <= Saddles.size(); i++){
System.out.print(Saddles.get(i) + " ");
}
}//end find Saddles
public static void findLowest(int columnNumber){
int lowest;
if(Grid[0] < Grid[1] || Grid[0] < Grid[2]){
lowest = Grid[0];
}
else{
if(Grid[1] < Grid[0] || Grid[1] < Grid[2]){
lowest = Grid[1];
}
else{
if(Grid[2] < Grid[1] || Grid[2] < Grid[1])
lowest = Grid[2];
}//end branching if loop
}
Saddles.add(lowest);
}//end of findLowest
}//end of Main
1) ошибки сообщают вам ** точно ** что не так - вы пытаетесь использовать меньше и больше, чем на массивах, а не на элементах, хранящихся в массивах, и 2) вы пытаетесь запустить код, который не будет компилироваться, - никогда не делайте этого. Сначала исправьте проблемы компиляции. –
С первого взгляда ваша функция 'findLowest()' кажется неправильной. Ваш алгоритм пытается сравнить два массива вместо двух чисел. – Santa
'' бит беспорядок, но еще не успел его очистить: «' - пожалуйста, найдите время, чтобы исправить это, прежде чем публиковать здесь. Это подразумевает что-то вроде: «У меня нет времени исправить это, но я ожидаю, что у вас будет время его прочитать». Мы очень ценим это, когда вы на самом деле ** делаете ** потратить время, чтобы облегчить нам помощь. –