Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.io.*;
- public class Homework6 {
- public static void main(String[] args)throws IOException {
- Scanner scan = new Scanner(System.in);
- System.out.println("Please enter filename");
- String FileName = scan.next();
- System.out.println("Enter a word to check:");
- String str = scan.next();
- scanSTR(str, FileName);
- scan.close();
- }
- public static void scanSTR(String str, String FileName) throws IOException{
- File inputFile = new File(FileName);
- Scanner in = new Scanner(inputFile);
- String verified = "";
- while (in.hasNext()) {
- String input = in.next();
- if (input.contains(str))
- verified += in.next();
- }
- System.out.println(verified);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement