Solved

boolean condition issue

Posted on 2014-10-02
4
129 Views
Last Modified: 2014-10-04
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

Why i get above error. how to fix it. please advise
0
Comment
Question by:gudii9
  • 2
  • 2
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 40358670
if(  13<=a && a<=19 ){
0
 
LVL 7

Author Comment

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

is different from

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

Please advise
0
 
LVL 7

Author Comment

by:gudii9
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

by:
ozo earned 500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Bartender Integration Builder 3 44
Delphi: barcode reading on android platform 1 51
java example issue 3 23
Link failure 16 34
The purpose of this article is to demonstrate how we can use conditional statements using Python.
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
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…

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question