Spaces:
Running
Running
File size: 567 Bytes
1a3f91a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
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.
|