Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# boolean condition issue

Posted on 2014-10-02
Medium Priority
145 Views
Hi,

I was working one belw challenge

http://codingbat.com/prob/p178986

I wrote solution as below

public boolean hasTeen(int a, int b, int c) {
if((13<=a<=19)){
return true;
}
if((13<=b<=19)){
return true;
}
if((13<=c<=19)){
return true;
}
else return false;
}

I get error as below

Error:      if((13<=a<=19)){
^^^^^^^^^^^
The operator <= is undefined for the argument type(s) boolean, int

see Example Code to help with compile problems

0
Question by:gudii9
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2
• 2

LVL 84

Expert Comment

ID: 40358670
if(  13<=a && a<=19 ){
0

LVL 7

Author Comment

ID: 40361547
How if(  13<=a && a<=19 ){

is different from

if((13<=a<=19)){

0

LVL 7

Author Comment

ID: 40361548
public boolean hasTeen(int a, int b, int c) {
if((13<=a && a<=19)){
return true;
}
if((13<=b && b<=19)){
return true;
}
if((13<=c && c<=19)){
return true;
}
else return false;
}

when i wrote as above all test cases passing
0

LVL 84

Accepted Solution

ozo earned 2000 total points
ID: 40361596
How if(  13<=a && a<=19 ){

is different from

if((13<=a<=19)){
The first is legal java code, the second is not

13<=a<=19  is interpreted as
(13<=a) <= 19
(13<=a) is a boolean, and 19 is an int,
trying to compare a boolean and an int with <= is invalid
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
###### Suggested Courses
Course of the Month5 days, 13 hours left to enroll