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);
}
}
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);
}
}