Bad operand types for binary operator java

Bad operand types for binary operator java

Это мой main метод. Я продолжаю получать следующее сообщение об ошибке при компиляции:

java: 21: ошибка: неправильные типы операндов для двоичного оператора ‘ java operators binary-operators

3 ответа

5 Tarun [2018-08-13 14:33:00]

Проблема связана с

5 deHaar [2018-08-13 14:12:00]

Прежде всего, вам не нужно проверять, есть ли N % 2 == 0 потому что, если это не так != 0 в вашей первой проверке, возможно только одно else , то есть == 0 .

Способ хранения кода, читаемого, может быть вложенным, если такие утверждения выглядят следующим образом:

The error shows this line

This is the whole code:

I’ve fixed the code:

Was an issue with the brackets, updated for anyone in the future.

3 Answers 3

== has higher precedence than & . You might want to wrap your operations in () to specify how you want your operands to bind to the operators.

Similarly for all parts of the if condition.

Because & has a lesser priority than == .

Your code is equivalent to a[0] & (1 == 0) , and unless a[0] is a boolean this won’t compile.

(yes, Java does hava a boolean & operator — a non shortcut logical and)

You have to be more precise, using parentheses, otherwise Java will not use the order of operands that you want it to use.

Not the answer you’re looking for? Browse other questions tagged java binary operand or ask your own question.

Linked

Related

Hot Network Questions

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2020 Stack Exchange Inc; user contributions licensed under cc by-sa 4.0 with attribution required. rev 2020.1.10.35756

Читайте также:  Dle ссылка на файл

I am programming a gas calculator and am stuck in a rut, how can I change this code to make it so my inputted numbers are able to be multiplied and divided?

public class GasCalculator

public static void main(String[]args)

//Pop up an input box with text (How many gallons does your tank hold ? )

String a=JOptionPane.showInputDialog(null,"How many gallons does your tank hold ?");

//Pop up an input box with text (What is your car’s fuel efficiency ?)

String b=JOptionPane.showInputDialog(null,"What is your car’s effieciency ?");

//Pop up an input box with text (What is the price per gallon ? )

String c=JOptionPane.showInputDialog(null,"What is the price per gallon ?");

//Pop up an input box with text (How many miles are you going ? )

String d=JOptionPane.showInputDialog(null,"How many miles are you going ?");

//Print into command prompt what you put into input dialog box

Ссылка на основную публикацию
Adblock detector