Solved

boolean condition issue

Posted on 2014-10-02
4
120 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
Comment Utility
if(  13<=a && a<=19 ){
0
 
LVL 7

Author Comment

by:gudii9
Comment Utility
How if(  13<=a && a<=19 ){

is different from

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

Please advise
0
 
LVL 7

Author Comment

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
This article will show, step by step, how to integrate R code into a R Sweave document
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now