日期:2014-05-20 浏览次数:20763 次
import java.util.*; public class firstname { static public Scanner input = new Scanner(System.in); static public LinkedList<String> fname; public firstname() { } /** * @category Write a program that reads in a series of first names and * stores them in a LinkedList. Do not store duplicate names. * Allow the user to search for a first name. * */ static String temp; public static void main(String args[]) { fname = new LinkedList<String>(); while (input.hasNext()) { temp = input.next(); for (int i = 0; i < fname.size(); i++) { if (temp.equals(fname.get(i))) continue; } fname.add(temp); } System.out.println("输入要找的名字"); //input.next(); temp = input.next(); temp = input.next(); for (int i = 0; i < fname.size(); i++) { if (temp.equals(fname.get(i))) System.out.printf("The index of %s is %d!", fname.get(i), i); } } }