Advertisement
vencinachev

Java-main-Files

Nov 16th, 2020
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.io.PrintWriter;
  4. import java.util.ArrayList;
  5. import java.util.Scanner;
  6.  
  7. public class Program {
  8.  
  9. public static void main(String[] args) {
  10. try {
  11. File inputFile = new File("data.txt");
  12. File outputFile = new File("dataout.txt");
  13. Scanner reader = new Scanner(inputFile);
  14. PrintWriter pw = new PrintWriter(outputFile);
  15. ArrayList<Student> stds = new ArrayList<Student>();
  16. int cnt = 0;
  17. while (reader.hasNextLine()) {
  18. String[] input = reader.nextLine().split(" ");
  19. stds.add(new Student(input[0], Integer.parseInt(input[1]), Double.parseDouble(input[2])));
  20. }
  21. for (Student s : stds) {
  22. if (s.getNumber() % 2 == 0) {
  23. pw.println(s);
  24. }
  25. }
  26. pw.close();
  27. reader.close();
  28. } catch (FileNotFoundException e) {
  29. e.printStackTrace();
  30. }
  31. }
  32.  
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement