Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.*;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- try {
- File f = new File("D://output.dat");
- if (f.createNewFile())
- System.out.println("Файл output.dat успешно создан");
- else {
- System.out.println("Файл output.dat уже есть, мы пересоздали его");
- f.delete();
- f.createNewFile();
- }
- System.out.print("Введите x: ");
- double x = in.nextDouble();
- int i = 0;
- String[] result = new String[23];
- try {
- BufferedWriter fout = new BufferedWriter(new FileWriter("D://output.dat"));
- for (double z = -0.5; z <= 6.22; z += 0.3) {
- double w = (2 * x) + (((2 * Math.PI * Math.sin(3 * x)) - Math.exp(Math.sqrt(2 * z))) / (Math.abs(1 + Math.pow(Math.log(z), 2))));
- if (!Double.isNaN(w)) {
- result[i] = w + "";
- fout.write(result[i] + '\n');
- }
- if (Double.isNaN(w)) {
- result[i] = "0";
- fout.write(result[i] + '\n');
- }
- }
- i++;
- fout.close();
- System.out.println("Запись завершена!");
- } catch (Exception e) {
- System.out.println("Запись не удалась!");
- }
- } catch (Exception e) {
- System.err.println(e);
- }
- //Вывод файла
- try {
- BufferedReader finput = new BufferedReader(new FileReader("D://output.dat"));
- String line = null;
- line = finput.readLine();
- while (line != null) {
- System.out.println(line);
- line = finput.readLine();
- }
- finput.close();
- } catch (Exception e) {
- System.out.println("Не удалось считать файл!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement