sfrsnyz

Корвяков ЯП7

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