Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- public class FileCl {
- public static void fileReading(FileInter fileInter) throws FileNotFoundException {
- fileInter.workFile();
- }
- }
- ///////
- import java.io.FileNotFoundException;
- public interface FileInter {
- void workFile() throws FileNotFoundException;
- }
- ///////////
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.PrintWriter;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) throws FileNotFoundException {
- File in=new File("Ввод.txt") ;
- File out1=new File("1.txt") ;
- File out2=new File("2.txt") ;
- File out3=new File("3.txt") ;
- FileCl.fileReading(() -> { //нахождение суммы всех чисел файла
- Scanner scanner=new Scanner(in);
- PrintWriter print=new PrintWriter(out1);
- int sum=0;
- while (scanner.hasNext()){
- sum+= scanner.nextInt();
- }
- print.println("Сумма всех чисел: "+sum);
- print.close();
- scanner.close();
- });
- FileCl.fileReading(() -> { //нахождение максимального элемента файла
- Scanner scanner=new Scanner(in);
- PrintWriter print=new PrintWriter(out2);
- int max=0;
- while (scanner.hasNext()){
- int temp=scanner.nextInt();
- if(temp>max)
- max=temp;
- }
- print.println("Масимальный элемент файла: "+max);
- print.close();
- scanner.close();
- });
- FileCl.fileReading(() -> { //нахождение минимального элемента файла
- Scanner scanner=new Scanner(in);
- PrintWriter print=new PrintWriter(out3);
- int min=2_147_483_647;
- while (scanner.hasNext()){
- int temp=scanner.nextInt();
- if(temp<min)
- min=temp;
- }
- print.println("Минимальный элемент файла: "+min);
- print.close();
- scanner.close();
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement