java - Search text file for matching integer -
i'm struggling program read through text file , find match number num
wrkid
, can print out relevant information.
the text file looks this. numbers 455 , 367 wrkid
, i'm trying number input match:
corner street^3^455^collin^sydney david street^2^367^spence^sydney
public class work { public static void main(string[] args) throws ioexception { scanner keyboard = new scanner(system.in); system.out.print("enter filename >> "); string response = keyboard.nextline(); file infile = new file(response); scanner wrk = new scanner(infile); system.out.print("enter job id >> "); int num = keyboard.nextint(); while (route.hasnextline()) { string street = wrk.nextline(); int stopnum = wrk.nextint(); int wrkid = wrk.nextint(); string road = wrk.nextline(); string town = wrk.nextline(); if(wrkid == num) { system.out.println("work id , street: " + trkid + street); } } } }
problem here:
string street = wrk.nextline(); int stopnum = wrk.nextint(); int wrkid = wrk.nextint(); string road = wrk.nextline(); string town = wrk.nextline();
when call wrk.nextline() assigning entire first line of text string street... if need integers, throw away other input using nextint();
Comments
Post a Comment