Search for an UID number input by the user and display the corresponding student name along with the UID number
Define a class to accept 10 students UID no’s and their corresponding names in two different
single dimensional arrays. Search for an UID number input by the user and display the
corresponding student name along with the UID number if found in the array, otherwise
display appropriate error message using Linear search technique
import java.util.*;
public class UIDname {
public static void main(String[] args) {
int flg=0;
Scanner sc=new Scanner(System.in);
String name[]=new String[10];
int uid[]=new int[10];
System.out.println("Enter 10 students name and their uid numbers");
for(int i=0;i<10;i++)
{
name[i]=sc.next();
uid[i]=sc.nextInt();
}
System.out.println("Enter an uid num to search");
int srch=sc.nextInt();
for(int i=0;i<10;i++)
{
if(uid[i]==srch)
{
System.out.println("Name : "+name[i]);
System.out.println("UID NUMBER "+uid[i]);
flg=1;
break;
}
}
if(flg==0)
System.out.println("UID number not found");
}
}
FOR CODE,
CLICK : https://onecompiler.com/java/3y4eg7brb (TO FIND OUTPUT)