This is what I've got so far. I'm trying to use split so that it would print out a specific item (country names from the input file) but I'm not entirely sure how to do it and there's some errors where I'm doing the split.
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
public class test {
public static void main(String[] args) throws FileNotFoundException {
readFile("sample1.txt");
}
//creates a method that opens the file
public static void readFile(String fileName) throws FileNotFoundException {
File text = new File(fileName);
Scanner reader = new Scanner(text);
while (reader.hasNextLine()) {
//splits the text file to print out specific columns
String[] data = reader.nextLine().split(" ");
System.out.println(data);
}
reader.close();
}
}
Input file:
1 China Japan 2 2
2 Korea India 2 2
3 Korea India 1 2
4 Korea Germany 1 2
5 Japan Germany 5 8
6 India Japan 5 8
7 India Japan 8 10
8 China Korea 6 9
Output I'm looking for:
Package one ships from China to Japan
Package two ships from Korea to India