Advertisement
Mancolo

Домашняя работа №11

Mar 17th, 2021
945
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.29 KB | None | 0 0
  1.     package com.company;
  2.     import java.util.*;
  3.     import java.util.Scanner;
  4.  
  5.     public class Main {
  6.         public static void main(String[] args) {
  7.             System.out.println("===Первое задание===");
  8.             try
  9.             {
  10.                 FileReader fReader = new FileReader("test1.txt");
  11.                 Scanner sc = new Scanner(fReader);
  12.  
  13.                 while (sc.hasNextLine())
  14.                 {
  15.                     String data = sc.nextLine();
  16.                     System.out.println(data);
  17.                 }
  18.             } catch (FileNotFoundException e) {
  19.                 System.out.println("Ошибка чтение из Файла");
  20.                 e.printStackTrace();
  21.             }
  22.             System.out.println("===Второе задание===");
  23.             try
  24.             {
  25.                 FileReader fReader = new FileReader("test1.txt");
  26.                 Scanner sc = new Scanner(fReader);
  27.                 int res = 0;
  28.  
  29.                 while (sc.hasNextLine())
  30.                 {
  31.                     String data = sc.nextLine();
  32.                     for (int i = 0; i < data.length(); i++) {
  33.                         if (data.charAt(i) == 'e') {
  34.                             res++;
  35.                         }
  36.                     }
  37.                 }
  38.                 System.out.println(res);
  39.             } catch (FileNotFoundException e) {
  40.                 System.out.println("Ошибка чтение из Файла");
  41.                 e.printStackTrace();
  42.             }
  43.  
  44.             System.out.println("===Третье задание===");
  45.  
  46.             try
  47.             {
  48.                 FileReader fReader = new FileReader("test1.txt");
  49.                 Scanner sc = new Scanner(fReader);
  50.                 String nun = "", longestWord = "";
  51.  
  52.                 while (sc.hasNextLine())
  53.                 {
  54.                     nun = sc.next();
  55.                     if (nun.length() > longestWord.length()) {
  56.                         longestWord = nun;
  57.                     }
  58.  
  59.                 }
  60.                 System.out.println(longestWord);
  61.             } catch (FileNotFoundException e) {
  62.                 System.out.println("Ошибка чтение из Файла");
  63.                 e.printStackTrace();
  64.             }
  65.  
  66.  
  67.         }
  68.  
  69.     }
  70.  
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement