dimanche 29 juillet 2018

How to search for a name from a text file

// how do I make the scanner find a name case insensitive? For example if Emily is in the text file.

import java.util.; import java.io.;

public class BabyNames {

public static void main(String[] args) throws FileNotFoundException {
    Scanner console = new Scanner(System.in);
    System.out.println("** Popularity of a baby name since year 1920 **");
    System.out.print("name? ");
    String name = console.next();

    Scanner input = new Scanner(new File("names.txt"));
    while (input.hasNext()) {
        String search = input.next();
        if (search = name) { // need help here

        }
    }
}

}

Aucun commentaire:

Enregistrer un commentaire