0% found this document useful (0 votes)
9 views1 page

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 views1 page

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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy