KaiquanMah commited on
Commit
1a3f91a
·
verified ·
1 Parent(s): 20953aa

Create 10a. Logical operators

Browse files
Week 1: Types, condition clauses and loops/10a. Logical operators ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Logical operators
2
+ Explanation Java
3
+ and && a && b
4
+ or || a || b
5
+ not ! !a
6
+
7
+
8
+ //eg
9
+ //number is between 10 and 20
10
+ import java.util.Scanner;
11
+
12
+ public class Example {
13
+ public static void main(String[] args) {
14
+ Scanner reader = new Scanner(System.in);
15
+ System.out.print("Give a number: ");
16
+ int num = Integer.valueOf(reader.nextLine());
17
+
18
+ if (num > 10 && num < 20) {
19
+ System.out.println("Number is between 10 and 20.");
20
+ }
21
+ }
22
+ }
23
+ Example output:
24
+ Give a number: 17
25
+ Number is between 10 and 20.
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+