I'm stuck with this exercise, I have to match the input of an user and a word on a txt file, and that match has to show the whole line, but I don't know how to do it, I have code but I am not sure if it is correct
//codes01.dat
IXE, Mangalore, India
BOM, Mumbai, India
PPP, Proserpine Queensland, Australia
RKT, Ras Al Khaimah, United Arab Emirates
Input: ProseRPine
Output: PPP, Proserpine Queensland, Australia
import java.io.*;
import java.util.*;
public class pruebas
{
public static void main(String[] args) throws java.io.IOException
{
System.out.print(" enter airport name");
Scanner keyboard = new Scanner(System.in);
String input = keyboard.nextLine();
BufferedReader br = new BufferedReader(new FileReader("codes01.dat"));
String s1;
String s2;
String strline;
while (strline = br.readLine())
{
s1 = br.readLine();
int numTokens = 0;
StringTokenizer st = new StringTokenizer(s1);
while (st.hasMoreTokens()) {
s2 = st.nextToken();
++numTokens;
if (s2.equalsIgnoreCase(input)) {
System.out.pritn(s1);
} else {
System.out.print(" no data found ");
}
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire