This question already has an answer here:
public class Test{
public static void main(String[] args) {
int test;
if(test = 1){
System.out.println("ok");
}
}
}
What would the result be? I ran it and it just says that it is an error and I can't do it but when i was taught this in school, my teacher told my that this would make it so that if(test = 1) would assign test to 1 in the brackets and then the if statement would read it as being if(1) and then the if statement would see it as being true since any value above 0 would be a true for the if statement.
This is clearly not the case in this program, so it what my teacher said false, or what? This is for my assignment btw, i don't want to get this wrong.
Aucun commentaire:
Enregistrer un commentaire