• Register
1 vote
79 views

Problem:

Hi! I’m a high school level student and learning Java in class and I have a homework assignment where I have to complete quizzes and exercises online. I need help with a couple of exercises but I solved most of them except one. The problem is to find out the minimum and maximum value by using an If block. But the program is not running and throws back an error: java bad operand types for binary operator. Here is my code snippet

public boolean inRange(int number, int minimum, int maximum){
           if(minimum <= number <= maximum){
              return false;
              }
           else{
              return true;
              }
}

Could any of you please figure out the contagious portion from the program? Thanks.

12 7 7
15,250 points

Please log in or register to answer this question.

2 Answers

1 vote

Solution:

In java, some operators are not companionable. The ( <= ) is one of them. You can’t use the operator in a java program. That’s the reason you are getting the error. So, what should you do now? You need to think of other algorithms and operators to solve the problem. I am giving you a hint of an algorithm below. Please, write the code for your own.

Lets the numbers be a, b, c and 

check if a>b if TRUE {

then check a>c (if it is true then print a as largest) else print c as largest }  

else { b>a 

check if b>c (if it is true then print b as largest) else print c as largest) }.

 

13 9 6
94,260 points
0 votes

Solution:

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

((a[0] & 1) == 0)

Likewis for all parts of the if condition.

Since & has a lesser priority than ==.

Your code is equivalent to a[0] & (1 == 0), and if not a[0] is a boolean this won't compile…

You require to:

(a[0] & 1) == 0

or You can attempt this way

The error message is pretty clear: you can't liken an Object with an int.
In case you are certain the low1 collection really conceive ints, then cast it properly, for example

int x = (int)low1.get(a);
for (int i = 0; i < row; i++) {
  if (dc[i][a] == x) {
    i1.add(i);
  }
}

By the way it would better applying the generic collections (that is ArrayList<E>[^]).

10 6 4
31,120 points

Related questions

0 votes
1 answer 15 views
15 views
Fix it.
asked Feb 6 TeamScript 13.5k points
0 votes
1 answer 19 views
19 views
I want to end the loop after the correct input. Help me to solve this problem.
asked Dec 16, 2020 TeamScript 13.5k points
0 votes
1 answer 32 views
32 views
I have a Java project I am working on and I get this error. I was working on that. I just want to know how to do that?
asked Dec 3, 2020 TeamScript 13.5k points
0 votes
0 answers 9 views
9 views asked Feb 23 Hira 2.2k points
0 votes
0 answers 53 views
53 views
I just made a new django project, pushed it to git and now I am trying to go deploy it using Digital ocean. I installed all the needful things like pip, python etc. but I am not able to make the python manage.py runserver work. ((g-v) is my virtualenv so that is not the problem.) ... 0 singledispatch 3.4.0.3 six 1.12.0 typing 3.7.4 virtualenv 16.7.3 virtualenv-clone 0.5.3 wheel 0.33.6 wrapt 1.11.2
asked Oct 27, 2020 psandprop 2.4k points
0 votes
1 answer 286 views
286 views
I want to know how to trace the count of 1 in the binary representation.
asked Sep 17, 2020 Daniel Anderson 4k points
0 votes
1 answer 5 views
5 views
Problem: i don&rsquo;t understand this problem? please help me. binary ' ' no operator found which takes a right-hand operand of type
asked Apr 16 Rohit kr 17.5k points
0 votes
1 answer 17 views
17 views
Can any one tell the reason for this?
asked Dec 19, 2020 TeamScript 13.5k points
0 votes
1 answer 9 views
9 views
Problem: I cannot figure out a problem I am having with code written in Python 2.7. I am converting the references to ints, but I keep getting a type exception bad operand type for unary +: 'str'. Can anyone assist?
asked Mar 16 ummesalma 29.2k points
0 votes
1 answer 33 views
33 views
Problem: I cannot figure out a problem I am having with code written in Python 2.7. I am hitting the operand exception bad operand type for unary +: 'str' when it gets to if int(splitLine[0]) > int(lastUnix): even though both values being compared print out as ints when tested.
asked Feb 24 Mashhoodch 13k points