Spaces:
Running
Running
| Logical operators | |
| Explanation Java | |
| and && a && b | |
| or || a || b | |
| not ! !a | |
| //eg | |
| //number is between 10 and 20 | |
| import java.util.Scanner; | |
| public class Example { | |
| public static void main(String[] args) { | |
| Scanner reader = new Scanner(System.in); | |
| System.out.print("Give a number: "); | |
| int num = Integer.valueOf(reader.nextLine()); | |
| if (num > 10 && num < 20) { | |
| System.out.println("Number is between 10 and 20."); | |
| } | |
| } | |
| } | |
| Example output: | |
| Give a number: 17 | |
| Number is between 10 and 20. | |