String Searching

package array;
 import java.util.Scanner;
  public class Array {
      static String last;
   public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
        String search;
        class1 c = new class1();
        c.students();
   
        System.out.println("Student # : " + last);
      
    }
}
//SubClass
package array;
import static array.Array.last;
import java.util.Scanner;
public class class1{
      Scanner scan = new Scanner(System.in);
        public void students(){
        System.out.print("Enter number of Students: ");
    int numOfStudents = Integer.parseInt(scan.nextLine());
    String names[] = new String[numOfStudents];
        for (int i = 0; i < names.length; i++) {
    System.out.print("Enter the name of Student " + (i+1) + " : ");  
    names[i] = scan.nextLine();
        }
        System.out.println("Enter the name of last Student: ");
        last = scan.next();
        for (int i = 0; i < names.length; i++) {
    System.out.print("Student " + (i+1) + " : ");
    System.out.print(names[i] + "\n");
        }
      }
}

Comments

Popular Posts