<= cannot be applied to boolean, int ?!?

M

machoextreme

I was experimenting with an homework assignment(it called for
if-then-else statements, which I finished thanks to some help from this
forum), and was trying to see if I could accomplish it using boolean
operators. However I get the following error operator <= cannot be
applied to boolean, int. Any idea why?!?
import java.util.*;

public class activities2
{
public static void main(String[] args)
{
int temp;
String act=null;
boolean swim = (temp > 85);
boolean tennis = ( 70 < temp <= 85);
boolean golf = (32 < temp <= 70);
boolean skiing = (0 < temp <= 32);
boolean dancing = (temp <= 0);
Scanner keyboard= new Scanner(System.in);
System.out.println("In order to decide what is the best activity at
the present time, please enter the current temperature ");
temp = keyboard.nextInt();
if (swim)
act = "Swimming";
else if (tennis)
act = "Tennis";
else if (golf)
act = "Golf";
else if (skiing)
act = "Skiing";
else if (dancing)
act = "Dancing";
System.out.println("The recommened activity for the current
temperature is " + act);




}
}
 
D

ddk

For example: 70 < temp <= 85
The result of " 70 < temp " is boolean, i.e. true or false.
What's the result of " boolean <= 85 " ?
It's obvious that the expression is wrong.
 
M

machoextreme

So your saying the reason why the expression doesn't work is that I'm
trying to evaluate a result, and not a varaible. So if I change the
boolean to boolean tennis =(70< temp) || (temp<= 85) would that be more
accurate?
 
D

ddk

you are right. but the statement should be :
boolean tennis =(70< temp) && (temp<= 85)
 
A

Adam Maass

machoextreme said:
I was experimenting with an homework assignment(it called for
if-then-else statements, which I finished thanks to some help from this
forum), and was trying to see if I could accomplish it using boolean
operators. However I get the following error operator <= cannot be
applied to boolean, int. Any idea why?!?
import java.util.*;


< cannot be applied to boolean.

< on int has a boolean return type. Boolean cannot be assigned to an int
variable.

-- Adam Maass
 
T

Thomas G. Marshall

Adam Maass said something like:
< cannot be applied to boolean.

< on int has a boolean return type. Boolean cannot be assigned to an int
variable.

I believe that he understands /that/ as such. What he was doing was
attempting a compound comparison similar to

(a < b < c)

Where the first a<b becomes the boolean.

--
Puzzle: You are given a deck of cards all face down
except for 10 cards mixed in which are face up.
If you are in a pitch black room, how do you divide
the deck into two piles (may be uneven) that each
contain the same number of face-up cards?
Answer (rot13): Sebz naljurer va gur qrpx, qrny bhg
gra pneqf naq syvc gurz bire.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,978
Messages
2,570,178
Members
46,713
Latest member
Zohan0786

Latest Threads

Top