0% found this document useful (0 votes)
9 views

Java Question

Uploaded by

Shivani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Java Question

Uploaded by

Shivani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.util.

Scanner;
import java.util.*;
class Student{
int studentID;
String studentName;
float studentMarks;

public Student(int studentID,String studentName,float studentMarks){


this.studentID=studentID;
this.studentName=studentName;
this.studentMarks=studentMarks;
}
}
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
sc.nextLine();
Student[] students=new Student[n];
for(int i=0;i<students.length;i++){
int studentID=sc.nextInt();
sc.nextLine();
String studentName=sc.nextLine();
float studentMarks=sc.nextFloat();
students[i]=new Student(studentID,studentName,studentMarks);
}
System.out.println("Enter the name to be searched");
sc.nextLine();
String name=sc.nextLine();

int searchName=FindStudentName(students,name);
if(searchName==-1){
System.out.println("Student not found");
}
else
System.out.println("Student Found with the id" + searchName);

}
public static int FindStudentName(Student[] students,String name){

for(int i=0;i<=students.length-1;i++){

if(students[i].studentName.equalsIgnoreCase(name)){
return students[i].studentID;
}
}
return -1;
}

You might also like