-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcts_11.java
More file actions
89 lines (64 loc) · 1.73 KB
/
Copy pathcts_11.java
File metadata and controls
89 lines (64 loc) · 1.73 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
Problem Statement –
IIHM institution is offering a variety of courses to students. Students have a facility to check whether a particular course is available in the institution. Write a program to help the institution accomplish this task. If the number is less than or equal to zero display “Invalid Range”.
Assume maximum number of courses is 20.
Sample Input 1:
Enter no of course:
5
Enter course names:
Java
Oracle
C++
Mysql
Dotnet
Enter the course to be searched:
C++
Sample Output 1:
C++ course is available
Sample Input 2:
Enter no of course:
3
Enter course names:
Java
Oracle
Dotnet
Enter the course to be searched:
C++
Sample Output 2:
C++ course is not available
Sample Input 3:
Enter no of course:
0
Sample Output 3:
Invalid Range
*/
import java.util.*;
public class cts_11 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the no. of courses:");
int n=sc.nextInt();
if(n<1||n>20){
System.out.println("Invalid range");
System.exit(0);
}
String s[]=new String[n];
System.out.println("Enter the course names:");
for(int i=0;i<n;i++){
s[i]=sc.next();
}
System.out.println("Enter the course to be searched");
String x=sc.next();
sc.close();
int f=-1;
for(int i=0;i<s.length;i++){
if(s[i].equalsIgnoreCase(x)){
System.out.println(x+" course is available");
f=0;
break;
}
}
if(f==-1)
System.out.println(x+" course not available");
}
}