Another noob first post asking for help
Hey, from what you can probably gather from the title, I have like no experience with java. Only previous programming is from 2 high school courses in visual basic .Net
Anyways, on to the point. I have been reading the java starter guides and decided to try my hand at some practice, so I checked out javabat, and decide to try my hand at one (can't link yet I guess.)
Basically, I need to take a value and determine if it is within 10 of either 100 or 200. Here is my code so far
Code:
public class Main {
public static void main(String[] args) {
int n;
n = 45;
isNear(n);
if(isNear == true){
System.out.println("The value is near 100 or 200");
}else{
System.out.println("The Value is not near 100 or 200");
}
}
public static boolean isNear(int a){
a = Math.abs(a);
if(100 - a <= 10 || 200 - a <= 10 || 110 - a <= 10 || 210 - a <= 10){
return true;
}else{
return false;
}
}
}
Now netbeans tells me it compiles ok, but it doesn't, and the error is from this line:
Code:
if(isNear == true){
I guess my question is, how do you compare booleans ? Is there a method I missed ?
Also, feel free to criticize my sloppy code, I would rather get a good grasp now than a year down the road.
Many thanks.
//Edit; I found the Math.abs method and cleaned it up a little bit