import java.io.*; import java.util.StringTokenizer; public class arvest1{ public static void main(String argumendid[]) throws IOException{ BufferedReader klaviatuur=new BufferedReader( new InputStreamReader(System.in) ); System.out.println("Palun tekstifailinimi: "); String failinimi=klaviatuur.readLine(); System.out.print("Palun kirjuta siia sona mille ees olevaid sonu soovid leida: "); String sona1=klaviatuur.readLine(); BufferedReader sisse=new BufferedReader( new FileReader(failinimi) ); System.out.print("Need sonad on: "); String lause=sisse.readLine(); String sona2=null; String sona3=null; while(lause!=null){ StringTokenizer st=new StringTokenizer(lause, " "); while(st.hasMoreTokens()){ sona2=sona3; sona3=st.nextToken(); if(sona3.startsWith(sona1))System.out.println(sona2); } lause=sisse.readLine(); } } }