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

Lab 1ex1

The document discusses a lab exercise on 1D and 2D arrays and linear search. It involves storing student names in an array, inputting a letter, and outputting the students whose names start with that letter.

Uploaded by

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

Lab 1ex1

The document discusses a lab exercise on 1D and 2D arrays and linear search. It involves storing student names in an array, inputting a letter, and outputting the students whose names start with that letter.

Uploaded by

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

CS212T: DATA STRUCTURE TERM: 1ST

TERM(2023)

LAB 01: ARRAYS(1D&2D) AND LINEAR SEARCH

Lab Exercise 1:

Model Answer:
public static void main(String[] args) {

Scanner input= new Scanner(System.in);


String students[]= new String[5];
System.out.println("Please enetr students names:");
for(int i=0; i<students.length;i++){
students[i]=input.nextLine();

}
System.out.println();
System.out.println("Enter the first letter of the names:" );
char l=input.next().charAt(0);
System.out.println();
LookAt(students,l);

public static void LookAt(String students[], char letter){


System.out.println("Students start with letter "+letter+" are:" );

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


if(students[i].charAt(0)==letter)
System.out.println(students[i]);
}
}

You might also like