I have a file which contains a sentence "Alina ma pingwina a w basenie delfina". So my program should show Alina/pingwina/w/delfina.
My code looks like this:
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
And the result is:public class zad679 { public static void main(String[] args) { try { FileReader fileReader = new FileReader("src/zad679/test.txt"); BufferedReader bufferedReader = new BufferedReader(fileReader); String content; List<String> l = new ArrayList<String>(); while ((content = bufferedReader.readLine()) != null) { l.add(content); for (int i =0; i < l.size(); i += 2) { System.out.println(l.get(i) + "/"); } } fileReader.close(); } catch (IOException e) { e.printStackTrace(); } } }
Alina ma pingwina a w basenie delfina/
So the sentence is just like in file, program doesn't display every second world from file like it should. What am I missing, how to fix it? Thank you for your help in advance