EduLearn - Online Education Platform

Welcome to EduLearn!

Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.

Browse Courses

=== Student Management Menu ===

1. Add Student

2. Display All Students

3. Search Student by Roll No

4. Remove Student

5. Exit

Enter your choice: 1

Enter Roll No: 101

Enter Name: aaa

Student added successfully!

 

=== Student Management Menu ===

1. Add Student

2. Display All Students

3. Search Student by Roll No

4. Remove Student

5. Exit

Enter your choice: 2

 

All Students:

Roll No: 101, Name: aaa

 

=== Student Management Menu ===

1. Add Student

2. Display All Students

3. Search Student by Roll No

4. Remove Student

5. Exit

Enter your choice: 3

Enter Roll No to search: 101

Roll No: 101, Name: aaa

 

=== Student Management Menu ===

1. Add Student

2. Display All Students

3. Search Student by Roll No

4. Remove Student

5. Exit

Enter your choice: 3

Enter Roll No to search: 100

Student not found.

 

=== Student Management Menu ===

1. Add Student

2. Display All Students

3. Search Student by Roll No

4. Remove Student

5. Exit

Enter your choice: 4

Enter Roll No to remove: 101

Student removed.

 

=== Student Management Menu ===

1. Add Student

2. Display All Students

3. Search Student by Roll No

4. Remove Student

5. Exit

Enter your choice: 5

Exiting program

import java.util.ArrayList;

import java.util.Scanner;

 

class Student {

int rollNo;

String name;

 

Student(int rollNo, String name) {

this.rollNo = rollNo;

this.name = name;

}

}

 

class StudentManagement {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

ArrayList<Student> students = new ArrayList<>();

 

do

{

System.out.println(“\n Student Management Menu “);

System.out.println(“1. Add Student”);

System.out.println(“2. Display All Students”);

System.out.println(“3. Search Student by Roll No”);

System.out.println(“4. Remove Student”);

System.out.println(“5. Exit”);

System.out.print(“Enter your choice: “);

int choice = sc.nextInt();

sc.nextLine();

switch (choice) {

case 1:

{

System.out.print(“Enter Roll No: “);

int rollNo = sc.nextInt();

sc.nextLine();

System.out.print(“Enter Name: “);

String name = sc.nextLine();

students.add(new Student(rollNo, name));

System.out.println(“Student added successfully!”);

break;

}

case 2:

System.out.println(“\nAll Students:”);

for (Student s : students) {

System.out.println(“Roll No: ” + s.rollNo + “, Name: ” + s.name);

} break;

case 3:

{

System.out.print(“Enter Roll No to Search: “);

int rollNo = sc.nextInt();

boolean found = false;

for (Student s : students) {

if (s.rollNo == rollNo) {

System.out.println(“Student Found: Roll No: ” + s.rollNo + “, Name: ” + s.name);

found = true;

break;

}

} if (!found) {

System.out.println(“Student not found!”);

} break;

}

case 4:

{

System.out.print(“Enter Roll No to Remove: “);

int rollNo = sc.nextInt();

boolean removed = false;

for (int i = 0; i < students.size(); i++) {

if (students.get(i).rollNo == rollNo) {

students.remove(i);

System.out.println(“Student removed successfully!”);

removed = true;

break;

}

} if (!removed) {

System.out.println(“Student not found!”);

} break;

}

case 5:

System.out.println(“existing the program..”);

break;

default:

System.out.println(“Invalid choice”);

break;

}

}while(choice!=5);

}

}

Java practice programs in data structure

Leave a Reply

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

EduLearn - Online Education Platform

Welcome to EduLearn!

Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.

Browse Courses

Popular Courses

[Course Image]

Introduction to Programming

Learn the fundamentals of programming with Python in this beginner-friendly course.

12 Hours Beginner
[Course Image]

Data Science Essentials

Master the basics of data analysis, visualization, and machine learning.

20 Hours Intermediate
[Course Image]

Web Development Bootcamp

Build modern websites with HTML, CSS, JavaScript and popular frameworks.

30 Hours Beginner
[Course Image]

Digital Marketing Fundamentals

Learn SEO, social media marketing, email campaigns and analytics.

15 Hours Beginner
Educational Website Footer