Advertisement
sfrsnyz

Petrov YAP 7

May 21st, 2021
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1.  
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.io.PrintWriter;
  6. import java.util.Scanner;
  7.  
  8. public class Main {
  9. public static void main(String[] args) throws FileNotFoundException {
  10. File f=new File("Ввод.txt") ;
  11. PrintWriter p1 =new PrintWriter(new File("1.txt"));
  12. PrintWriter p2 =new PrintWriter(new File("2.txt"));
  13. PrintWriter p3 =new PrintWriter(new File("3.txt"));
  14. Cls.doing((Inter) (p, f1) -> { //подсчет количества чисел файла
  15. Scanner scanner=new Scanner(f);
  16. int counter=0;
  17. while (scanner.hasNext()){
  18. scanner.nextInt();
  19. counter++;
  20. }
  21. p1.println("Количество чисел файла: "+counter);
  22. p1.close();
  23. scanner.close();
  24. },p1,f);
  25. Cls.doing((Inter) (p, f1) -> { //подсчет количества положительных чисел файла
  26. Scanner scanner=new Scanner(f);
  27. int counter=0;
  28. while (scanner.hasNext()){
  29. if(scanner.nextInt()>0)
  30. counter++;
  31. }
  32. p2.println("Количество положительных чисел файла: "+counter);
  33. p2.close();
  34. scanner.close();
  35. },p2,f);
  36. Cls.doing((Inter) (p, f1) -> { //подсчет количества отрицательных чисел файла
  37. Scanner scanner=new Scanner(f);
  38. int counter=0;
  39. while (scanner.hasNext()){
  40. if (scanner.nextInt()<0)
  41. counter++;
  42. }
  43. p3.println("Количество чисел файла: "+counter);
  44. p3.close();
  45. scanner.close();
  46. },p3,f);
  47. }
  48. }
  49.  
  50. //////////
  51.  
  52.  
  53. import java.io.File;
  54. import java.io.FileNotFoundException;
  55. import java.io.PrintWriter;
  56.  
  57. public interface Inter {
  58. void writer(PrintWriter p, File f) throws FileNotFoundException;
  59. }
  60.  
  61. /////////////
  62.  
  63.  
  64. import java.io.File;
  65. import java.io.FileNotFoundException;
  66. import java.io.PrintWriter;
  67.  
  68. public class Cls {
  69. public static void doing(Inter inter, PrintWriter p, File f) throws FileNotFoundException {
  70. inter.writer(p,f);
  71. }
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement