Java Program of Search a Course

Question:

IIHT 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

Code:

Course.java

import java.util.*;
public class Course
{
    public static void main (String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter no of course:");
        int no_crs=sc.nextInt();
        if(no_crs>0)
                  { 
                    System.out.println("Enter course names:");
                
                    String crs[]=new String[no_crs];
                    
                    for(int i=0;i<no_crs;i++)
                    {
                        crs[i]=sc.next();
                    }
                    
                    System.out.println("Enter the course to be searched:");
                    String srch=sc.next();
                    
                    int flag=0;
                    for(int i=0;i<no_crs;i++)
                    {
                        if(srch.equals(crs[i]))
                        {
                            flag++;
                        }
                    }
                    
                    if(flag!=0)
                    {
                        System.out.println(srch+" course is available");
                    }
                    else
                    {
                        System.out.println(srch+" course is not available");
                    }
                }
                else
                {
                    System.out.println("Invalid Range");
                }
        
    }
}

Recommended:

  1. Array square
  2. Generate number using odd digits
  3. Alternate Number Difference
  4. Next Greatest number
  5. Mark Comparison
  6. Print the characters in descending order
  7. Vowels in a fishBowl
  8. Least offer
  9. Ascending and descending order
  10. Mail Domain
  11. Count repeating words
  12. Sentence – Convert to upper and lower
  13. Count consecutive repeating characters
  14. Zig zag Array
  15. Pass and Fail Count
  16. Search a Course
  17. Average and Grade Calculation
  18. String – Find and replace the character (first occurrence)
  19. Sort the first and second half of an array
  20. Retail Shop
  21. Palindrome
  22. Numerology
  23. InitCap
  24. Array Compatiblilty
  25. Sum of the maximum and the minimum element
  26. String Concatenation
  27. Find Average Age
  28. Login
  29.  

Leave a Comment

Your email address will not be published. Required fields are marked *

x