Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.*;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- System.out.println("===Первое задание===");
- try
- {
- FileReader fReader = new FileReader("test1.txt");
- Scanner sc = new Scanner(fReader);
- while (sc.hasNextLine())
- {
- String data = sc.nextLine();
- System.out.println(data);
- }
- } catch (FileNotFoundException e) {
- System.out.println("Ошибка чтение из Файла");
- e.printStackTrace();
- }
- System.out.println("===Второе задание===");
- try
- {
- FileReader fReader = new FileReader("test1.txt");
- Scanner sc = new Scanner(fReader);
- int res = 0;
- while (sc.hasNextLine())
- {
- String data = sc.nextLine();
- for (int i = 0; i < data.length(); i++) {
- if (data.charAt(i) == 'e') {
- res++;
- }
- }
- }
- System.out.println(res);
- } catch (FileNotFoundException e) {
- System.out.println("Ошибка чтение из Файла");
- e.printStackTrace();
- }
- System.out.println("===Третье задание===");
- try
- {
- FileReader fReader = new FileReader("test1.txt");
- Scanner sc = new Scanner(fReader);
- String nun = "", longestWord = "";
- while (sc.hasNextLine())
- {
- nun = sc.next();
- if (nun.length() > longestWord.length()) {
- longestWord = nun;
- }
- }
- System.out.println(longestWord);
- } catch (FileNotFoundException e) {
- System.out.println("Ошибка чтение из Файла");
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement