forked from Nnamdikeshi/Java2545examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeatherPreferences.java
More file actions
40 lines (25 loc) · 1.35 KB
/
Copy pathWeatherPreferences.java
File metadata and controls
40 lines (25 loc) · 1.35 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
35
36
37
38
39
40
package week1_variables_if_else;
import java.util.Scanner;
public class WeatherPreferences {
//Create two scanners, one for Strings, and one for numbers - int and float values.
//Use this scanner to read text data that will be stored in String variables
static Scanner stringScanner = new Scanner(System.in);
//Use this scanner to read in numerical data that will be stored in int or double variables
static Scanner numberScanner = new Scanner(System.in);
public static void main(String args[]) {
// Finding out if someone likes any of Minnesota's weather.
System.out.println("Do you like snow? Answer Y for yes");
String likesSnow = stringScanner.nextLine();
System.out.println("Do you like thunderstorms? Answer Y for yes");
String likesStorms = stringScanner.nextLine();
//Use an OR condition - testing if person likes at least one of the things!
if (likesSnow.equalsIgnoreCase("Y") || likesStorms.equalsIgnoreCase("Y")) {
System.out.println("You like at least some of Minnesota's weather");
}
// ... and here.
// Close scanners. Good practice to clean up resources you use.
// Don't try to use scanners after this point. All code that uses scanners goes above here.
stringScanner.close();
numberScanner.close();
}
}