0

Вот код :

import java.util.*;

public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner io = new Scanner(System.in);
        int a = io.nextInt();
        int b = io.nextInt();
        int c = io.nextInt();
        int d = io.nextInt();
        if (a >= 0 || b >= 0 || c >= 0 || d >= 0){
        if (a = b && c = d){
            int area1 =a*c;
            System.out.println (area1);}
        else if (a = c && b = d){
            int area2 =a*b;
            System.out.println (area2);}
        else if (a = d && c = b){
            int area3 =a*c;
            System.out.println (area3);};}
        else
            System.out.println ("NOT POSSIBLE");
    }
} ```

А вот ошибка компайлера :
```Solution.java:14: error: bad operand types for binary operator '&&'
        if (a = b && c = d){
                  ^
  first type:  int
  second type: int
Solution.java:14: error: incompatible types: int cannot be converted to boolean
        if (a = b && c = d){
              ^
Solution.java:17: error: bad operand types for binary operator '&&'
        else if (a = c && b = d){
                       ^
  first type:  int
  second type: int
Solution.java:17: error: incompatible types: int cannot be converted to boolean
        else if (a = c && b = d){
                   ^
Solution.java:20: error: bad operand types for binary operator '&&'
        else if (a = d && c = b){
                       ^
  first type:  int
  second type: int
Solution.java:20: error: incompatible types: int cannot be converted to boolean
        else if (a = d && c = b){
                   ^

В чем прикол operand types я не знаю. Задачей было проверить возможность построения ПРЯМОугольника и, если это возможно, вычислить его площадь

1 ответ 1

2

Вместо a = b && c = d используйте a == b && c == d (и в аналогичных случаях). Ваше выражение должно состоять из булевых операций. Операция = означает присваивание.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.