-
Notifications
You must be signed in to change notification settings - Fork 375
/
Copy pathCourse.java
35 lines (28 loc) · 1022 Bytes
/
Course.java
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
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
class Course {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n;
System.out.println("Enter no of course:");
n = scanner.nextInt();
if (n <= 0) {
System.out.println("Invalid Range");
} else {
Set<String> courses = new HashSet<>();
System.out.println("Enter course names:");
for (int i = 0; i < n; ++i) {
String course = scanner.next();
courses.add(course);
}
System.out.println("Enter the course to be searched:");
String courseToBeSearched = scanner.next();
if (courses.contains(courseToBeSearched)) {
System.out.println(courseToBeSearched + " course is available");
} else {
System.out.println(courseToBeSearched + " course is not available");
}
}
}
}