Java operator cannot be applied to long

Operator ‘>’ cannot be applied to ‘int[][]’

В общем, надо в двумерном массиве найти минимум и максимум. Массив нужен целочисленный, но если искать эти самые минимумы и максимумы, то всё становится плохо. Нигде не мог найти ответ.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
import java.io.*; public class main { public static void main(String[] args) { int[][] numbers = new int[5][5]; for(int i = 0; i  5; i++) { for(int j = 0; j  5; j++) { numbers[i][j] = (int) (Math.random()*256); } } for(int i = 0; i  5; i++) { for(int j = 0; j  5; j++) { System.out.print(numbers[i][j] + " "); } System.out.print("\n"); } int[][] max = new int[0][0]; int[][] min = new int[0][0]; for(int i = 0; i  5; i++) { for(int j = 0; j  5; j++) { if (numbers > max) { // Вот тут ошибка появляется. } } } } }

Не понимаю почему выдает ошибку «Operator ‘>’ cannot be applied to operands of type ‘object’ and ‘int'»
Здравствуйте. У меня проблема с кодом, не понимаю почему выдает ошибку. private void.

Operator ‘/’ cannot be applied to ‘void’, ‘float’
Не пойму в чем ошибка с void, как это можно разделить? static Money delenMoney(Money a, Money b).

Источник

operator cannot be applied to int, java.lang,string

Hey again,
I’m having another problem unfortunately. We were asked to create a tree that has binary tree properties as well as max heap property.
(take A(7),C(8) and B(3) ; the tree should be so that the it should alphabetically represent a binary tree and numerically represent a heap) I tried to create a treap but didn’t succeed. so I thought that I’d create a priority queue and sort the items numerically and then remove them one by one and add to the tree, which will sort them in alphabetical order (The best I could come up with). Now the problem is with the priority queue, it gives me an «operator < cannot be applied to int, java.lang,string " error msg.

public class PriorityQueue < public String createString(int item, String str) < String space, priort; priort = Integer.toString(item); space = " "; totl = str + space + priort; return totl; >public int insertFirst(int item, String keys) < String str = createString(item, keys); insert(str, item); >public void insert(String str, int item) < int i; if (nItems == 0) < queArray[nItems++] = str; // insert at 0 >else < for (i = nItems - 1; i >= 0; i--) < if (item < queArray[i]) < // the error appears here queArray[i + 1] = queArray[i]; >else < break; >> queArray[i + 1] = str; nItems++; > (nItems > 0) > public void EmptyQueque() < while (!isEmpty()) < remove(); >> public void remove() < if ((!isEmpty())) < while (!isEmpty()) < String str = queArray[--nItems]; System.out.println(str + " "); >> public static void main(String[] args) < PriorityQueue thePQ = new PriorityQueue(100); thePQ.insertFirst(3, "H"); thePQ.insertFirst(10, "M"); thePQ.insertFirst(2, "O"); thePQ.insertFirst(5, "Hfsh"); thePQ.remove(); >>

I wanted to have the createString method because it would be easier for me to just remove items and send it to the tree (is there another method?).
I understand that you can’t compare int with the string inside the array but I’m really stuck here and haven’t got any ideas.
Is there a way to add a string and integer in to a two-dimensional array or something?
Sorry about the long boring explanation, and thanx for taking the time to read it.
Any help will be much appreciated.

Источник

operator && cannot be applied to boolean,int — error

send pies

posted 12 years ago

  • Report post to moderator
  • So I am compling a program that is due tonight and I cannot get past these errors.

    I really need help on this one!

    I keep getting the following errors.

    Can anyone help me PLEASE. Desperate! I am having to use an online complier at the moment as I cannot access the remote one I am supposed to use for school.

    Thanking everyone in advance.

    send pies

    posted 12 years ago

  • Report post to moderator
  • this tells you that there is no method called nextint(). Right, change it to nextInt();
    When you have doubts about names, properties of a class look in oracle/sun docs online. This is just 1 error less, more remain.

    PS : what is this code trying to do ? please describe it for ease of understanding.

    send pies

    posted 12 years ago

  • Report post to moderator
  • Main.java:31: operator && cannot be applied to boolean,int
    invalidEntry = (direction != left && Left && right && Right && down && Down && up && Up)
    ^

    && can only take boolean values ie, anything that can be true or false. Nothing else is allowed. Why are you giving it ints ?
    M&&N means both M and N must evaluate to a boolean. eg. M can be (4>5) which is false. So the part after && is not evaluated. Since , && is a short-circuit operator(google it!).

    PS : I would suggest that you refer your textbook for such theory. Which one do you use ?

    send pies

    posted 12 years ago

  • Report post to moderator
  • Surely you need to initiliaze your left and right ints, or your direction will never equal them, and you probably want to use the logical or operator || instead of &&.

    You’re on a gravy train with biscuit wheels Roy.

    send pies

    posted 12 years ago

  • Report post to moderator
  • My task is to write a program that calculates and displays a position of a point inside a square. Position of a point in the plane is specified by its coordinates, two numbers: x and y, often written as a pair (x,y). The position of the point is repeatedly changed by the user who enters a direction for the point to move: up, down, left or right. Then one of the point’s coordinates, x or y, will increase or decrease by one unit. Initially the point lies at (0,0) which is the centre of a square whose sides are 8 units long. If the user enters ‘l’ (for left) or ‘r’ (for right) then the first coordinate, x, will decrement or increment, respectively. Similarly, the second coordinate, y, will increment or decrement if the user enters ‘u’ (for up) or ‘d’ (for down).

    I am an external student and am using «Starting out with Java», trust me it is not my best subject.

    I have done some more work and changed things around and now only have 8 errors but they are all on the same line!

    send pies

    posted 12 years ago

  • Report post to moderator
  • The error is on line 48 and basically revolves around the try

    Main.java:48: illegal character: \8220
    System.out.print(“Invalid entry, try again”);
    ^
    Main.java:48: ‘;’ expected
    System.out.print(“Invalid entry, try again”);
    ^
    Main.java:48: not a statement
    System.out.print(“Invalid entry, try again”);
    ^
    Main.java:48: ‘;’ expected
    System.out.print(“Invalid entry, try again”);
    ^
    Main.java:48: ‘ System.out.print(“Invalid entry, try again”);
    ^
    Main.java:48: illegal character: \8221
    System.out.print(“Invalid entry, try again”);
    ^
    Main.java:48: not a statement
    System.out.print(“Invalid entry, try again”);
    ^
    Main.java:48: ‘try’ without ‘catch’ or ‘finally’
    System.out.print(“Invalid entry, try again”);
    ^
    8 errors

    send pies

    posted 12 years ago

    • 1
  • Report post to moderator
  • The double quotes on that line don’t look like regular double quotes but rather like fancy ones a word processor might use. Java does not recognize those.

    Источник

    Читайте также:  Django python sql query
    Оцените статью