Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 f=new File("Ввод.txt") ;
- PrintWriter p1 =new PrintWriter(new File("1.txt"));
- PrintWriter p2 =new PrintWriter(new File("2.txt"));
- PrintWriter p3 =new PrintWriter(new File("3.txt"));
- Cls.doing((Inter) (p, f1) -> { //подсчет количества чисел файла
- Scanner scanner=new Scanner(f);
- int counter=0;
- while (scanner.hasNext()){
- scanner.nextInt();
- counter++;
- }
- p1.println("Количество чисел файла: "+counter);
- p1.close();
- scanner.close();
- },p1,f);
- Cls.doing((Inter) (p, f1) -> { //подсчет количества положительных чисел файла
- Scanner scanner=new Scanner(f);
- int counter=0;
- while (scanner.hasNext()){
- if(scanner.nextInt()>0)
- counter++;
- }
- p2.println("Количество положительных чисел файла: "+counter);
- p2.close();
- scanner.close();
- },p2,f);
- Cls.doing((Inter) (p, f1) -> { //подсчет количества отрицательных чисел файла
- Scanner scanner=new Scanner(f);
- int counter=0;
- while (scanner.hasNext()){
- if (scanner.nextInt()<0)
- counter++;
- }
- p3.println("Количество чисел файла: "+counter);
- p3.close();
- scanner.close();
- },p3,f);
- }
- }
- //////////
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.PrintWriter;
- public interface Inter {
- void writer(PrintWriter p, File f) throws FileNotFoundException;
- }
- /////////////
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.PrintWriter;
- public class Cls {
- public static void doing(Inter inter, PrintWriter p, File f) throws FileNotFoundException {
- inter.writer(p,f);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement