forked from Nnamdikeshi/Java2545examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAboveFreezingElseElseIf.java
More file actions
34 lines (24 loc) · 1.05 KB
/
Copy pathAboveFreezingElseElseIf.java
File metadata and controls
34 lines (24 loc) · 1.05 KB
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
package week1_variables_if_else;
import java.util.Scanner;
public class AboveFreezingElseElseIf {
static Scanner stringScanner = new Scanner(System.in);
static Scanner numberScanner = new Scanner(System.in);
public static void main(String[] args) {
System.out.println("Enter today's temperature in F");
double temp = numberScanner.nextDouble();
if (temp > 32) {
//This will run if the condition is true - if temp is greater than 32
System.out.println("It's above freezing");
} else if (temp == 32) {
//Another condition to check - we can also test if it is exactly 32
System.out.println("It's exactly freezing");
} else {
//If neither of the conditions are true, then this code will run.
System.out.println("It's below freezing");
}
//Indentation in if blocks is optional but strongly suggested
//It's a standard convention and helps readability
stringScanner.close();
numberScanner.close();
}
}